The content of this article is about PHP quickly pushing WeChat template messages. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
Original address : https://blog.csdn.net/wanlinzan/article/details/70171782
It is necessary to send template messages to following users. Since there are many following users on public accounts, so Using ordinary curl and other methods is too slow. Since template message sending does not need to wait for the result of WeChat, the fsockopen() function of PHP can be used to achieve the effect of rapid sending. The code is as follows:
$data = [ 'touser' => '11111111111111111', 'template_id' => '111111111111111111', 'url' => '11111111111111111111', 'data' => [ 'first' => [ 'value' => '1111111111111111111', 'color' => '#173177', ], 'keyword1' => [ 'value' => '111111111111111111', 'color' => '#173177', ], 'keyword2' => [ 'value' => date('Y年m月d日 H:i'), 'color' => '#173177', ], 'remark' => [ 'value' => '1111111111111111111111111', 'color' => '#173177', ] ] ];$access_token = '此处填写自己公众号的access_token';$params = json_encode($data,JSON_UNESCAPED_UNICODE);$start_time = microtime(true); for ($i = 0; $i < 50; $i++) { $fp = fsockopen('api.weixin.qq.com', 80, $error, $errstr, 1); $http = "POST /cgi-bin/message/template/send?access_token={$access_token} HTTP/1.1\r\nHost: api.weixin.qq.com\r\nContent-type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($params) . "\r\nConnection:close\r\n\r\n$params\r\n\r\n"; fwrite($fp, $http); fclose($fp); } print_r(microtime(true) - $start_time);
** The above code sent 50 template messages. Please see the running results for the time:
0.83637619018555
You can also use curl or even curl to send template messages. Batch processing method (multi-threading), but the relatively faster one should be the above method. **
##Original address: https://blog.csdn.net/wanlinzan/article/details/70171782
The above is the detailed content of PHP quickly pushes WeChat template messages. For more information, please follow other related articles on the PHP Chinese website!