Of course, the idea of remotely capturing data on the WeChat public platform was born, of course, the first thought of CURL.
CURL can be submitted remotely. I feel that WeChat is a proposal for us. No verification code will appear as long as it is not a malicious interface.
Several Important Issues
1. The remote logon interface is the HTTPS protocol.
2. After successful logon, the page jumps.
3. The returned HTML page can be output directly.
The following describes how to write a CURL.
| The code is as follows: |
Copy code |
// Bind an account to WeChat remote logon Public function Curl_login ($ username, $ pwd ){ $ Config_token = "XiaoDengPHP "; $ Pwd = md5 ($ pwd ); $ Url = "https://mp.weixin.qq.com/cgi-bin/login? Lang = zh_CN "; $ PostArray = array ("username =". $ username, "pwd =". $ pwd, "imgcode =", "f = json "); $ Fields = implode ("&", $ postArray ); $ Filedir = $ _ SERVER ['document _ root']. "/Cookies "; $ Cookie_file = $ filedir. "/cookie.txt "; $ Ch = curl_init (); www.111cn.net Curl_setopt ($ ch, CURLOPT_URL, $ url ); Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, 0 ); Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 1); // indicates https protocol submission Curl_setopt ($ ch, CURLOPT_HEADER, 0); // the header section is not returned. Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0 )"); Curl_setopt ($ ch, CURLOPT_POST, 1 ); Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ fields ); Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); // generates Cookies and stores them in the specified directory. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return the information obtained by curl_exec () in the form of a file stream instead of directly outputting it. Curl_setopt ($ ch, CURLOPT_REFERER, "https://mp.weixin.qq.com/cgi-bin/login? Lang = zh_CN "); // jump $ Result = curl_exec ($ ch ); Return json_decode ($ result ); // Close the CURL session Curl_close ($ ch ); } |
The above method is implemented, remotely logging on to the WeChat public platform, the next thing is to change the account to the developer mode, the same CURL.
Note that this curl requires cookies instead of cookies.
The key code is to verify the server. You need to set a server connection and a token.
| The code is as follows: |
Copy code |
Public function auth ($ token) { $ Data = array ( $ _ GET ['timestamp'], $ _ GET ['nonce '], $ Token ); $ Sign = $ _ GET ['signature']; Sort ($ data ); $ Signature = sha1 (implode ($ data )); If ($ signature ===$ sign ){ Echo ($ _ GET ['echostr']); Exit; } Else { Return false; } } |
In this way, if the service is successfully activated, a message of MES = 302 json data and a token authenticated by WeChat platform will be returned.
As long as you are careful, you will find that the TOKEN in the WeChat connection is dynamically changing, but it remains unchanged for a period of time.
Therefore, you need this token to construct a URL to obtain other page information.
However, you must have encountered a very bad problem during the discovery process.