首页
源码
关于
Search
1
luhn验证
9 阅读
2
git协同开发
7 阅读
3
微信公众号发送模版消息
7 阅读
4
银联商务支付对接
6 阅读
5
mysql大批量插入数据
5 阅读
PHP
Socket
Java
MYSQL
JS
Vue
ThinkPHP
Git
ts
Mac
登录
/
注册
Search
标签搜索
thinkphp
PHP
微信小程序
银联商务支付
支付
银联
luhn
luhn校验
mysql
mysql大批量插入数据
insert
load指令
tp
订阅消息
仓库
远程仓库
git仓库
git
git协同开发
微信
404
累计撰写
17
篇文章
累计收到
0
条评论
首页
栏目
PHP
Socket
Java
MYSQL
JS
Vue
ThinkPHP
Git
ts
Mac
页面
源码
关于
搜索到
1
篇与
的结果
2022-07-02
微信订阅消息
小程序订阅消息推送1.获取用户openid2.用户授权消息推送(订阅几次可发送几次)3.后端组合数据调用微信api发送订阅消息 getTmplID: function () { wx.requestSubscribeMessage({ tmplIds: ['模版id'], success(res) { console.log(res) if(res['模版id'] === 'accept') { console.log('授权成功') wx.showToast({ title: '订阅OK!', duration: 1000, }) /*****服务器主动推送的话,不需要调用***************/ wx.request({ method: 'POST', url: '后端接口', //不是josn格式 header: { 'content-type': 'application/json' }, data: { }, //调用接口成功 success: function (res) { console.log("请求成功",res); } }); } }, fail(err) { //失败 console.error(err); reject() } }) }<?php declare (strict_types = 1); namespace app\index\controller; use think\facade\View; use think\facade\Db; use think\Request; class Wx { public function sendMessage() { $appid = 'appid'; $appsecret = 'appsecret'; $touser = '用户openid';//用户openid $template_id = '订阅模板id';//所需下发的订阅模板id $page = 'pages/my/my';//跳转页面不填则模板无跳转。 $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret; $res = json_decode(file_get_contents($url), true); $access_token = $res['access_token']; //请求url $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=' . $access_token; //发送内容 $data = []; //接收者(用户)的 openid $data['touser'] = $touser; //所需下发的订阅模板id $data['template_id'] = $template_id; //点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。 $data['page'] = $page; //模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } } $data['data'] = [ "character_string1" => [ 'value' => '46546546' ], "date2" => [ 'value' => '2022年6月30日 12:00' ], "thing3" => [ 'value' => '122' ], 'thing6' => [ 'value' => '22' ], ]; //跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版 $data['miniprogram_state'] = 'developer' ; return self::curlPost($url,json_encode($data)) ; } //发送post请求 static function curlPost($url,$data) { $ch = curl_init(); $params[CURLOPT_URL] = $url; //请求url地址 $params[CURLOPT_HEADER] = FALSE; //是否返回响应头信息 $params[CURLOPT_SSL_VERIFYPEER] = false; $params[CURLOPT_SSL_VERIFYHOST] = false; $params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回 $params[CURLOPT_POST] = true; $params[CURLOPT_POSTFIELDS] = $data; curl_setopt_array($ch, $params); //传入curl参数 $content = curl_exec($ch); //执行 curl_close($ch); //关闭连接 return $content; } }
2022年07月02日
3 阅读
0 评论
0 点赞