作者 sgj
1 个管道 的构建 通过 耗费 2 秒

审核通过后发送模板消息

@@ -9,7 +9,9 @@ @@ -9,7 +9,9 @@
9 namespace app\admin\controller; 9 namespace app\admin\controller;
10 10
11 11
  12 +use app\user\model\UserModel;
12 use cmf\controller\AdminBaseController; 13 use cmf\controller\AdminBaseController;
  14 +use EasyWeChat\Foundation\Application;
13 15
14 16
15 /** 17 /**
@@ -91,6 +93,25 @@ class ApprovalController extends AdminBaseController @@ -91,6 +93,25 @@ class ApprovalController extends AdminBaseController
91 $update['answer']=input('answer'); 93 $update['answer']=input('answer');
92 $result=db('engage')->where($map)->update($update); 94 $result=db('engage')->where($map)->update($update);
93 if ($result==1){ 95 if ($result==1){
  96 + /*发送模板消息*/
  97 + $user_id=db('engage')->where($map)->value('user_id');
  98 + $User=new UserModel();
  99 + $openid=$User->getUserOpenid();
  100 +
  101 + $userId = $openid;
  102 + $templateId = 'M0PtJ9xxGWkMoCI6p1ZhQLyj83k3PAqkeG94yyMRxD4';
  103 + $url = 'http://overtrue.me';
  104 + $data = array(
  105 + "keyword1" => "恭喜你购买成功!",
  106 + "keyword2" => "巧克力",
  107 + "keyword3" => "39.8元",
  108 + "keyword4" => "欢迎再次购买!",
  109 + );
  110 +
  111 + $Wechat=new Application();
  112 + $notice = $Wechat->notice;
  113 + $result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
  114 + var_dump($result);
94 $this->success('审核成功!'); 115 $this->success('审核成功!');
95 }else{ 116 }else{
96 $this->error('审核失败!'); 117 $this->error('审核失败!');
@@ -455,4 +455,15 @@ class UserModel extends Model @@ -455,4 +455,15 @@ class UserModel extends Model
455 ->select(); 455 ->select();
456 return $user; 456 return $user;
457 } 457 }
  458 +
  459 + /**
  460 + * 获取用户openid
  461 + * @param $user_id
  462 + * @return mixed
  463 + */
  464 + public function getUserOpenid($user_id){
  465 + $map['user_id']=$user_id;
  466 + return db('third_party_user')->where($map)->value('openid');
  467 + }
  468 +
458 } 469 }