Daily AV-WeChat public platform-instance-PHP source code

Source: Internet
Author: User
Daily AV-public platform-how to deploy your own public platform for instances:
1. open http://mp.weixin.qq.com registration/login
2. go to the advanced functions menu and select edit mode or developer mode (this example belongs to developer mode-you need to own the server)
3. enter the developer mode, register as a developer, and configure the interface information. For example:
URL: http: // 192.168.1.1/wx_sample.php
Token: weixin (enter one by yourself)
4. open wx_sample.php $ wechatObj-> valid (); this method is used for verification.
5. the verification is successful. disable wx_sample.php $ wechatObj-> valid ();
6. use your mobile phone to access your own public platform.


Test method of this sample code:
1. open your mobile phone
2. follow the public account: Daily AV
3. send a message: q: Beijing Meets Seattle
4. return a magnetic link.
5. the system returns the Thunder magnetic link. Please download and watch it with your computer or mobile phone.

Principle:

1. receive user data, for example, q Beijing Meets Seattle

2. go to the bt search engine to query data

3. return a magnetic link.

Ps: because I have not been qualified for beta testing, many functions are restricted. for example, 5 Seconds of timeout cannot be solved,

Unable to actively push, batch push, simulated login, and so on...

 Valid (); // $ wechatObj-> responseMsg (); class wechatCallbackapiTest {private $ keyword; public function valid () {$ echoStr = $ _ GET ["echostr"]; // valid signature, option if ($ this-> checkSignature () {echo $ echoStr; exit ;}} public function responseMsg () {// get post data, May be due to the different environments $ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; // extract post data if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ fromUsername = $ postObj-> FromUserName; $ toUsername = $ postObj-> ToUserName; $ this-> keyword = trim ($ postObj-> Content); $ time = time (); $ textTpl ="
                             
  %s
                              
  %s
                              
  
   
% S
                              
  %s
                              
  %s
                              
  
   
0
                              
 "; If (! Empty ($ this-> keyword) {if ($ this-> keyword = 999) {$ msgType = "text"; $ contentStr = 'when you search: q When you meet Seattle in Beijing, the system returns the Thunder magnetic link. Please download and watch it with the computer or mobile version of Thunder. '; //' Parameter: 1, query by download quantity; parameter: 2, query by time; parameter: 5, query by quality; add double quotation marks for exact query; example: q "Beijing Meets Seattle" 1'; echo $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr); exit ;} preg_match ('# ^ q (. *) # ', $ this-> keyword, $ str); if ($ str [1]) {$ data = $ this-> getQueryParam ($ str [1]); $ contents = $ this-> getQueryList ($ data); $ resutl = $ this-> getQueryResult ($ contents); $ link = str_replace ('&','&', urldecode ($ res Utl [1]); // assemble the magnetic link if ($ link) {$ msgType = "text"; $ contentStr = $ link; echo $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr) ;}} else {$ msgType = "text"; $ contentStr = 'Enter q for query, for example: q for more help in meeting Seattle in Beijing, enter 999 '; echo $ resultStr = sprintf ($ textTpl, $ fromUsername, $ toUsername, $ time, $ msgType, $ contentStr );}} else {echo "Input something... ";}} else {echo" "; exit ;}} Private function checkSignature () {$ signature = $ _ GET ["signature"]; $ timestamp = $ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ tmpArr ); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpStr ==$ signature) {return true;} else {return false ;}} // return q = query function getQueryResult ($ contents) {$ result = array (); preg_m Atch ('# \ [magnet-link \] # iUs', $ contents, $ content); $ result = $ content; return $ result ;} // Obtain the query data function getQueryList ($ data) {$ data ['order'] = $ data ['order']? $ Data ['order']: 0; $ data ['P'] = 0; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL ,' https://btdigg.org/search ? '. Http_build_query ($ data); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_USERAGENT, 'Google Bot '); curl_setopt ($ ch, CURLOPT_TIMEOUT, 4 ); curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($ ch, CURLOPT_FRESH_CONNECT, true); $ result = curl_exec ($ ch); curl_close ($ ch); return $ result ;} // Obtain the query parameter function getQueryParam ($ str) {$ data = array (); $ string = explode ('', $ str ); // Is the array and the last array is the number $ last = array_pop ($ string); if (is_numeric ($ last )) {$ data ['Q'] = implode ('', $ string); $ data ['order'] = $ last ;} else {$ data ['Q'] = $ str;} return $ data ;}}?>

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.