PHP quick push template message, php mail template message
The template message needs to be sent to the paying user. Because there are many paying users with public accounts, it is too slow to use common curl and other methods. Because the template message is sent without waiting for results, you can use the fsockopen () function of php to quickly send messages. The Code is as follows:
$ Data = ['touser' => '000000', 'template _ id' => '000000', 'url' => '000000 ', 'data' => ['first' => ['value' => '000000', 'color' => '# 100',], 'keyword1 '=> ['value' => '000000', 'color' =>' #111111111111111111 ',], 'keyword2 '=> ['value' => date ('y, m, D, H: I'), 'color' => '#173177',], 'remark' => ['value' => '123', 'c Olor '=>' #173177 ',]; $ access_token =' enter your own public account 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 $ params \ r \ n"; fwrite ($ fp, $ http ); fclose ($ fp);} print_r (microtime (true)-$ start_time );
The above code sends 50 template messages. For the time used, see the running result:
0.83637619018555
You can also use curl or curl to send template messages in batches (multiple threads). However, this method is faster.
The above is the PHP quick push template message introduced by xiaobian. I hope it will help you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!