/**
* 获取 access_token
*/
public function getAccessToken()
{
if ($wx = Config::get('wechat')) {
$url='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$wx['xcx_appid'].'&secret='.$wx['xcx_appsecret'];
$data=[];
$result = send_post($url,$data);
if ($result) {
$json = json_decode($result, true);
if (!$json || isset($json['errcode'])) {
$this->errCode = $json['errcode'];
$this->errMsg = $json['errmsg'];
return false;
}
$this->access_token = $json['access_token'];
return $this->access_token;
}
}
}
//发送模板消息
public function sendTemplateMessage($data){
if (!$this->access_token && !$this->getAccessToken()) {
return false;
}
//echo "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$this->access_token}";
//$result = send_post("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$this->access_token}",$data);
$url="https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={$this->access_token}";
$result = $this->https_request($url,$data,'json');
if ($result) {
$json = json_decode($result, true);
if (empty($json) || !empty($json['errcode'])) {
$this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
$this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
}
return $json;
}
return false;
}
$datas = array (
'keyword1' => array (
'value' => ''
),
'keyword2' => array (
'value' => ''
),
'keyword3' => array (
'value' => ''
),
'keyword4' => array (
'value' => '已完成'
),
'keyword5' => array (
'value' => '恭喜您,订单:'.$order['orderno'].'打卡任务全部完成'
)
);
$templateid='模板id';
$openid=$member['openid'];
$data = array ();
$data ['touser'] = $openid;
$data ['template_id'] = $templateid;
$data ['page'] = 'pages/wodekecheng_success/wodekecheng_success?id='. $order['productid'];
$data ['form_id'] = $formid;
$data ['data'] = $datas;
$result = $this->sendTemplateMessage ( $data );
版权声明:本文为u014465396原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。