PHP version Micro-credit public account third party management tool development Concise Tutorial _php Example

Source: Internet
Author: User
Tags curl html page

This article describes the PHP version of micro-credit public Accounts third-party management tool development methods. Share to everyone for your reference, specific as follows:

The API that was recently provided on the micro-trust platform, and so on, is really an API for getting user information.

So there is no way, can only own to obtain, manual filling of course can solve the problem, of course, programming is not to make life easier?

Of course, the idea of remote capture of micro-trust platform data arises spontaneously, of course, the first thought of curl.

Curl can be submitted remotely, I feel the micro-letter is proposed to let us how, as long as not a malicious brush interface, there will be no verification code.

A few key points to note:

① Telnet interface is the time of HTTPS protocol.
② Login successfully after the page has a jump.
The HTML page returned by ③ can be exported directly.

The following shows a specific curl

Micro-trust remote login binding account 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 ();
  curl_setopt ($ch, Curlopt_url, $url);
  curl_setopt ($ch, Curlopt_ssl_verifypeer, 0); curl_setopt ($ch, Curlopt_ssl_verifyhost, 1); The presentation is HTTPS protocol submitted curl_setopt ($ch, Curlopt_header, 0); does not return header part 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); Production of cookies and stored in the designated directory curl_setopt ($ch, curlopt_returntransfer,1);
  The information obtained by CURL_EXEC () is returned as a file stream, rather than as a direct output. curl_setopt ($ch, Curlopt_referer, "https://mp.weixin.qQ.com/cgi-bin/login?lang=zh_cn ");
  Jump Point $result = curl_exec ($ch);
  Return Json_decode ($result);
Closes the Curl session curl_close ($CH);

 }

The above method is realized, telnet to the micro-trust platform, the next thing is to make the account into a developer model, the same curl.

Note that this time the curl is going to take cookies instead of making cookies.

The key code is to verify the server's corresponding, you need to set up a server connection and a token

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;
    }


If the opening succeeds, it should return a mes=302 JSON data and a micro-platform certified token information.

As long as you are careful, you will find that the micro-letter connection inside the token is a dynamic change, but there is a period of time unchanged.

So you need this token to construct the URL to get additional page information.

But in the discovery process, you must encounter a very broken problem.

For more information on PHP related content readers can view the site topics: "PHP micro-credit Development Skills summary", "PHP coding and transcoding Operation skills Summary", "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP string (String) Usage Summary", "php+ MySQL Database operations Introduction tutorial and PHP Common database operation Skills Summary

I hope this article will help you with the PHP program design.

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.