This article mainly introduces the small program and PHP send template message notification, has a certain reference value, now share to everyone, the need for friends can refer to
First, the template message interface needs to be written on the background server. Append At present, the small program template message can only be triggered by himself and I. 】
2018.4.9 Revision:1 Submission Form can be issued 1, multiple submissions issued the number of independent, mutual does not affect;
1 Payment can be issued 3, multiple payment issued the number of independent, not affect each other.
Small program Side
According to the template information, the corresponding value in the background, as well as Formid or prepay_id, notify the person's OpenID.
. wxml file
Forget to add it before, because it has to be formid or prepay_id. So there has to be a button to trigger the acquisition. If you have no manual trigger method, please do not hesitate to enlighten!!!! This question has been thinking for a long time!!
<form bindsubmit= "Tixian" report-submit= ' true ' > <button class= ' btn ' form-type= ' submit ' disabled= ' {{ Lock}} "> Withdraw </button> </form>
. js file
/** * Trigger reminder */ remindmessage:function (formid) { var that = this wx.request ({ method: ' POST ', URL: ' https://www.**********************_message.php ',//Background interface data: { O_id:that.data.allthing.openid , U_name:that.data.allthing.userInfo.nickName, Money:that.data.money, formid:formid }, header: { ' content-type ': ' application/x-www-form-urlencoded ' }, success:function (res) { Console.log (res.data) }, }
Background interface
. php
<?phpinclude_once ('/o**********************c/function.php '); Include_once ('/o*************************on/ Config.php '), $ms = new Mysqls (), $o _id = intval ($_post[' o_id ')), $u _name = addslashes ($_post[' u_name '); $money = Floatval ($_post[' money '); $formid = addslashes ($_post[' formid '); $dated = Date ("y-m-d h:i:s"); $to _place = "purse"; $remark = "Balance approximately 0-5 business days to return your top-up account, please wait for the balance to the notice "; $template _id =" Zaw*******************4dy "; Template Id$access_token=m::get (' q******_ '. $appid);//need to use token. Put it in the cache!! if (! $access _token) {$url _access_token = ' https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential &appid= '. $appid. ' &secret= '. $secret; $json _access_token = Sendcmd ($url _access_token,array ()); Access_token Plus cache $arr _access_token = Json_decode ($json _access_token,true); $access _token = $arr _access_token[' Access_token '); M::set (' qub*************_ '. $appid, $access _token,3600);} if (! $o _id | |! $u _NAME | |! $money | |! $formid) {$arr = array (' ret ' =>0, ' msg ' =≫ ' Parameter Error! echo Json_encode ($arr);d ie ();} if (!empty ($access _token)) {$url = ' https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token= '. $access _token; The variable insertion string here cannot be used {}!!! $data = ' {' Touser ': '. $o _id. ' "," template_id ":" '. $template _id. ' "," form_id ":" '. $formid. ' "," data ": {" Keyword1 " : {"value": "'. $u _name. '" }, "Keyword2": {"value": "'. $money. '" }, "Keyword3": {"value": "'. $to _place. '" }, "Keyword4": {"value": "'. $dated. '" }, "Keyword5": {"value": "'. $remark. '" } }}'; $result = Sendcmd ($url, $data); $arr = Array (' ret ' =>1, ' msg ' = ' success ', ' Data ' =>array (' result ' = = $result), );} else {$arr = array (' ret ' =>0, ' msg ' = ' = ' ACCESS token is empty!) ');} echo Json_encode ($arr);/** * Initiate request * @param string $url Request address * @param string $data Request packet * @return String request return Data */function sendcmd ($url, $data) {$curl = Curl_init ();//Start a Curl session curl_setopt ($curl, Curlopt_url, $url); Access to the address curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Detection of the source of the certificate curl_setopt ($curl, Curlopt_ssl_verifyhost, 2); Check the SSL encryption algorithm from the certificate for presence of curl_setopt ($curl, Curlopt_httpheader, Array (' Expect: ')); Resolution packet large cannot be submitted curl_setopt ($curl, curlopt_followlocation, 1); Use automatic jump curl_setopt ($curl, Curlopt_autoreferer, 1); Auto set Referer curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packet curl_setopt ($curl, Curlopt_timeout, 30); Set timeout limit to prevent dead curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the Returned header area curl_setopt ($curl, Curlopt_returntransfer, 1); The information obtained is returned as a file stream $tmpInfo = curl_exec ($curl); Perform the action if (Curl_errno ($curl)) {echo ' errno '. Curl_error ($curl); } curl_close ($curl); Key Curl session return $tmpInfo; Return Data}?>