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

审核通过后发送模板消息

... ... @@ -9,7 +9,9 @@
namespace app\admin\controller;
use app\user\model\UserModel;
use cmf\controller\AdminBaseController;
use EasyWeChat\Foundation\Application;
/**
... ... @@ -91,6 +93,25 @@ class ApprovalController extends AdminBaseController
$update['answer']=input('answer');
$result=db('engage')->where($map)->update($update);
if ($result==1){
/*发送模板消息*/
$user_id=db('engage')->where($map)->value('user_id');
$User=new UserModel();
$openid=$User->getUserOpenid();
$userId = $openid;
$templateId = 'M0PtJ9xxGWkMoCI6p1ZhQLyj83k3PAqkeG94yyMRxD4';
$url = 'http://overtrue.me';
$data = array(
"keyword1" => "恭喜你购买成功!",
"keyword2" => "巧克力",
"keyword3" => "39.8元",
"keyword4" => "欢迎再次购买!",
);
$Wechat=new Application();
$notice = $Wechat->notice;
$result = $notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($userId)->send();
var_dump($result);
$this->success('审核成功!');
}else{
$this->error('审核失败!');
... ...
... ... @@ -455,4 +455,15 @@ class UserModel extends Model
->select();
return $user;
}
/**
* 获取用户openid
* @param $user_id
* @return mixed
*/
public function getUserOpenid($user_id){
$map['user_id']=$user_id;
return db('third_party_user')->where($map)->value('openid');
}
}
... ...