开发文档https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html
wx.requestSubscribeMessage({
tmplIds: ['0dXmr_02PQzpK1dL3BL_pias5XcaLEHlfyLwxQi_bkc'],
success(res) {
console.log('st')
console.log(res)
t.util.request({
url: "entry/wxapp/Mes",
data: {
openid: wx.getStorageSync("openid"),
// unionid: wx.getStorageSync("unionid")
page:'index'
},
success: function (ac) {
console.log(1111111);
console.log(ac);
}
})
},
fail(res) {
console.log('st2')
console.log(res)
}
})
开发文档https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
public function doPageMes(){
global $_W;
$uniacid = $_W["uniacid"];
$result = pdo_fetch("SELECT * FROM " . tablename("hyb_o2o_parment") . " where `uniacid`='{$uniacid}'");
$APPID = $result["appid"];
$SECRET = $result["appsecret"];
$tokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$APPID}&secret={$SECRET}";
$item=array();
$item['my_key'] = 'access_token';
$item['my_time'] = date("Y-m-d H:i:s",time());
$getArr = array();
$access_token = pdo_fetch("SELECT * FROM " . tablename("hyb_o2o_accesstiken"));
// exit();
//判断access_token是否储存在数据库,并且有值
if($access_token&&$access_token['my_value']){
$res = $this->wordTime($access_token['my_time']);
if($res>=2){
$item = array();
$tokenArr = json_decode($this->send_post($tokenUrl, $getArr, "GET"));
$access_token = $tokenArr->access_token;
$item['my_value'] = $access_token;
$res = pdo_update("hyb_o2o_accesstiken", $item, array("id" => $access_token["id"]));
$access_token = $access_token;
}else{
$access_token = $access_token['my_value'];
}
}else{
if($access_token){
$item = array();
$tokenArr = json_decode($this->send_post($tokenUrl, $getArr, "GET"));
$access_token = $tokenArr->access_token;
$item['my_value'] = $access_token;
$res = pdo_update("hyb_o2o_accesstiken", $item, array("id" => $access_token["id"]));
}else{
$tokenArr = json_decode($this->send_post($tokenUrl, $getArr, "GET"));
$access_token = $tokenArr->access_token;
$item['my_value'] = $access_token;
$res = pdo_insert("hyb_o2o_accesstiken", $item);
}
$access_token = $access_token;
}
$mesUrl = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={$access_token}";
$getArr = array();
$getArr['touser'] = $_REQUEST['openid'];
$getArr['page'] = $_REQUEST['page'];
$getArr['template_id'] = 'mobanid';
$getArr['miniprogram_state']='developer';
// $getArr['data'] = ;
$touser = $_REQUEST['openid'];
$page = $_REQUEST['page'];
$data = [
"touser"=>$touser, //接收用户的openid
"template_id"=>"mobanid", //模板id
"page"=>"$page",//点击模板消息跳转至小程序的页面
"data"=>[
"character_string1"=>[
"value"=> '11111',//自定义参数
],
"thing4"=>[
"value"=> 4444, //自定义参数
],
"amount3"=>[
"value"=> 123,//自定义参数
],
"time8"=>[
"value"=> date('Y-m-d H:i:s',time()),//自定义参数
],
"thing9"=>[
"value"=> "bbb",//自定义参数
]
]
];
// $query_data = json_decode(html_entity_decode(json_encode($query_data)));
// $mesArr = json_decode($this->send_post($mesUrl,json_decode(json_encode($query_data)), "POST"));
$mesArr = json_decode($this->https_curl_json($mesUrl,json_encode($data)));
// var_dump($mesArr);
}
网友评论