1、微信小程序
uni.requestSubscribeMessage({
//此处填写刚才申请模板的模板ID
tmplIds: ['UcjeP3a8vDFKpG6v56xfOK39ByqkhXCkkUoN1_Jsj8s'],
success (res) {
console.log(res)
}
})
2、php
/**
* 微信通知
* */
public function wx_tz($orderid){
$system = Db::query("select * from ims_zh_jdgjb_system where id = 2");
$appid = $system[0]['appid'];
$secret = $system[0]['appsecret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
$tmptoken = json_decode($res);
$token = $tmptoken->access_token;
$order = Db::query("select * from ims_zh_jdgjb_order where id='{$orderid}'");
$name = '';
if($order[0]['status'] == 1){
$name = '已付款';
}
if($order[0]['status'] == 4){
$name = '完成';
}
if($order[0]['status'] == 5){
$name = '入住';
}
$data = array(
"touser"=>$order[0]['openid'],
"template_id"=>"UcjeP3a8vDFKpG6v56xfOK39ByqkhXCkkUoN1_Jsj8s",
"page"=>"pages/index/index",
"miniprogram_state"=>"miniprogram_state",
"lang"=>"zh_CN",
'data'=>array(
'thing1'=>array('value'=>$order[0]['seller_name']),
'phrase2'=>array('value'=>$name),
'amount9'=>array('value'=>$order[0]['price']),
'thing19'=>array('value'=>$order[0]['room_type']),
),
);
$url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$token;
$re = $this->http_request($url,$data);
return $re;
}
public function http_request($url, $data = null)
{
$data = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}