You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
<?php
|
|
|
|
namespace app\base\controller\demo\api;
|
|
|
|
use think\App;
|
|
use think\facade\Request;
|
|
|
|
class Weixin extends Base
|
|
{
|
|
|
|
/**
|
|
* 发送模板消息
|
|
* @date 2022-03-26
|
|
*/
|
|
public function sendTemplate()
|
|
{
|
|
$weixin_param = get_weixin_config();
|
|
$template_class = new \tencent\wechat\weixin\Template($weixin_param);
|
|
|
|
|
|
// 发送模板消息
|
|
$data = [
|
|
'touser' => 'okuRis8VoZgHXUfIFQKKWhEQmn4I', //接收者openid
|
|
'template_id' => 'fdH3SheDR5DyCBqRRa98EyhncTbljXbFgHMdzx_R3us', //模板ID
|
|
'url' => 'https://www.baidu.com', //模板跳转链接(海外帐号没有跳转能力)
|
|
'data' => [ //模板数据,可以设定颜色,具体查看文档
|
|
'first' => '您的订单已取消',
|
|
'orderProductPrice' => '10.00',
|
|
'orderProductName' => '商品1',
|
|
'orderAddress' => '智慧山',
|
|
'orderName' => date("Ymd") . createNonceStr(4, ['number']),
|
|
'remark' => '具体查看详情'
|
|
],
|
|
];
|
|
$result = $template_class->sendTemplate($data);
|
|
dump($result);
|
|
// 记录日志
|
|
platformLog($data, $result, 'weixin_send_template_' . UID);
|
|
|
|
if($result['errcode'] != 0){
|
|
return sendErrorMessage($result['errcode'],$result['errmsg']);
|
|
}
|
|
|
|
|
|
}
|
|
}
|