PHP quick push of WeChat template messages and php mail template messages

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.