WeChat public account three-party platform development [pre_auth_code]

Today, I will tell you about an important parameter required to enter the authorization page, the pre-authorization code.

The pre-authorization code (ie pre_auth_code) is used for security verification when the WeChat official account authorizes the third-party platform. The result example seems to be another 10 minutes, and everyone can adapt according to the actual situation). The parameters we need to use in this step are component_access_token and component_appid.

Interface call request description

http request method: POST (please use https protocol)
https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=xxx

POST data example

{
"component_appid":"appid_value"
}

Request parameter description
parameter illustrate
component_appid third-party platform appid
Example of return result

{
"pre_auth_code":"Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
"expires_in":600
}

Description of result parameters
parameter illustrate
pre_auth_code pre-authorization code
expires_in Valid for 20 minutes
Specific program implementation

Public function get_pre_auth_code(){
$res = $this->component_detail();
$last_time = $res['pre_time'];
$pre_auth_code = $res['pre_auth_code'];
$difference_time = $this->validity($last_time);
if(empty($pre_auth_code) || $difference_time>1100){
$pre_auth_code = $this->get_pre_auth_code_again();
}
return $pre_auth_code;
}
Public function get_pre_auth_code_again(){
$component_access_token = $this ->get_component_access_token();
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token='.$component_access_token;
$param ['component_appid'] = $tt['appid'];
$data = post_data ( $url, $param );
$pre['pre_auth_code']= $data ['pre_auth_code'];
$pre['pre_time'] = date("Y-m-d H:i:s");
M('Public') ->where(array('id'=>1))->setField($pre);
return $data ['pre_auth_code'];
}

After obtaining the pre_auth_code in this step, the next thing you need to do is to generate the authorization page. For the specific generation and invocation of the authorization page, the WeChat official does not provide specific documentation, only the most important part of the "Technical Description of the Authorization Process". A simple example URL is given above, which may be another pit for developers who are new to third-party platforms. In the next issue, I will write down my development steps on this piece. Of course, the complete code will be posted for your reference.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325966371&siteId=291194637