Use the method. Add Fahuo_wechat () directly to the logic of the page; the function is to be referenced beforehand.
Functionfahuo_wechat ($shopid) {
if (_cfg ("Sendmobile")) {
$thisdb = System::load_sys_class ("model");
$access = Getaccesstoken ()//template ID API, etc.
$access _token= $access [' Access_token '];
$template _id= $access [' template_id '];
$sql = "SELECT * from ' @ #_member_go_record ' where ' shopid ' = ' $shopid ' and status = ' paid, not shipped, unfinished '";
$row = $thisdb->getlist ($sql);
$POSTURL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token= $access _token";
foreach ($rowas $k=> $v) {
$member _band= $thisdb->getone ("Select B_code,b_data from" @ #_member_band ' WHERE ' b_uid ' = ' $uid ' and b_data!= ' ");
if (Empty ($member _band)) {return false;}
if (!empty ($member _band[' B_data ')) {
$url =web_path. " /mobile/user/buydetail/". $shopid;
$mobile = $v [' Company_money '];
"Touser" => $member _band[' b_code '],//one person at a time
"template_id" => $template _id,
"Value" => "Hello,". $v [' username ']., your hand has been successfully assembled. ",
"Value" => $v [' Shopname '],
echo Date (' y-m-d h:i:s ', $itemlist [0][' Q_end_time '])
"Value" =>date (' y-m-d h:i:s ', $v [' time ']),
"Value" =>round ($v [' Moneycount ']). " Golden Beans ",
"Value" => "Click to view Details",
Https_request ($POSTURL, Json_encode ($data), $mobile)//The contents of the shipping notice. To a micro-trust server
The string combination of sent shipping prompts was successful. Ready to send.
Micro-letter Delivery Preparation
Functiongetaccesstoken () {
Access_token should be stored and updated globally, with the following code written to the file as an example
$path = g_caches. ' Access_token.json ';
$data = Json_decode (file_get_contents ($path), true);
if ($data [' Expire_time '] < time ()) {//Expires less than current time, description expires, need to be updated
$appid = $data [' AppID '];
$appsecret = $data [' Appsecret '];
$url = "Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= $appid &secret=$ Appsecret ";
$data = Json_decode ($json, true);
$access _token= $data [' Access_token '];
$thisdb = System::load_sys_class ("model");
$wechat = $thisdb->getone ("SELECT * from" @ #_wechat_config ' WHERE id = 1 ");//Get AppID
$data [' expire_time '] = time () + 300;//5 minute update. Ask for 500 times a day, no more than 2000 limits on the line.
The 300 here is best not to set too large. Otherwise, you will often be prompted to expire the token, unable to send a message. The official said 2 hours expired. It's a lie.
$data [' access_token '] = $access _token;
$data [' template_id ']= $wechat [' template_id '];
$data [' AppID ']= $wechat [' AppID '];
$data [' Appsecret ']= $wechat [' Appsecret '];
Fwrite ($fp, Json_encode ($data));
Functionhttps_request ($url, $data = null, $mobile = ') {
$curl = Curl_init ()//initialization of a curl session
curl_setopt ($curl, Curlopt_url, $url);//This is the URL address you want to retrieve with PHP. You can also set this option when initializing with the Curl_init () function
curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE);
curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE);
curl_setopt ($curl, Curlopt_post, 1);
curl_setopt ($curl, Curlopt_postfields, $data);
A string that passes all data as an HTTP "POST" operation.
curl_setopt ($curl, Curlopt_returntransfer, 1);
The information that is curl_exec () is returned in the form of a file stream, rather than direct output.
$output = curl_exec ($curl);
if (!strstr ($output, ": 0"))
If the message after the letter is not included in the receipt: 0, it must have not been sent successfully. So put the unsuccessful in the log. Easy to find the reason.
$path 1= g_caches. ' Access_token2.json ';//access_token2.json Save the directory for the log, please correspond to the modification.
File_put_contents ($path 1, $output, file_append);//file_append means saving the log in an append way
if (Strstr ($output, "40003") && $mobile)//If is 40003 description, the customer does not pay attention to us, sends the information to remind him.
_sendmobile ($mobile, ' please pay attention to our public number. Otherwise we will not receive the micro-letter notice, thank you. ');//
Returnjson_decode ($output);
Determine if the user name is a normal administrator
if (Strstr ($name, "gly"))
|