300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > sendTemplateMessage微信小程序消息推送 前段 + 后端(thinkphp3.2)

sendTemplateMessage微信小程序消息推送 前段 + 后端(thinkphp3.2)

时间:2020-04-01 15:52:48

相关推荐

sendTemplateMessage微信小程序消息推送 前段 + 后端(thinkphp3.2)

1.微信小程序中,在用户提交信息之后给用户一个反馈就是要微信信息发送

第一步通过表单时间拿到formid

第二步拿到token值这个之前的文章有的

第三步拿到请求链接的其他参数(需要注意data参数)

前段代码(注意:在开发者工具上formid 是"the formId is a mock one",需要用真机测试,才会有真实的formid。)

一定要记得写 report-submit-timeout

<form bindsubmit="apply" class='mgt20' report-submit='true' report-submit-timeout='2000'><view class='input'><input name='name' placeholder='孩子姓名' maxlength='8'></input></view><view class='input'><input name='phone' placeholder='联系方式' maxlength='11'></input></view><view class='input' wx:if='{{apply.input1}}'><input name='input1' placeholder='{{apply.input1}}' maxlength='11'></input></view><view class='input' wx:if='{{apply.input2}}'><input name='input2' placeholder='{{apply.input2}}' maxlength='11'></input></view><button class='btnapply' id='tab-con' formType="submit">生成二维码</button></form>//jsapply:function(e){var formId = e.detail.formId;console.log(formId)},

sendTemplateMessage

本接口应在服务器端调用,详细说明参见服务端API。

发送模板消息后端流程,按照微信文档上描述的操作,没有遇到问题。链接地址

我的后端代码,使用的thinkphp3.2,(记得仔细看文档哦)

public function wxsend(){$accessToken = I('post.token');$touser = I('post.openid');$templateid = I('post.templateid');$formid = I('post.formid');$page = I('post.page');$url="https://api./cgi-bin/message/wxopen/template/send?access_token={$accessToken}";$data=['touser'=>$touser, 'template_id'=>$templateid,'form_id'=>$formid,'page'=>$page, 'data'=>array('keyword1' => array('value' =>'美如斯沙发'),'keyword2' => array('value' =>16),'keyword3' => array('value' =>8),),];$data=json_encode($data);$result = $this->curl_post_https($url,$data);echo $result;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。