Home > Backend Development > PHP Tutorial > WeChat third-party login - php gets component_verify_ticket?

WeChat third-party login - php gets component_verify_ticket?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:39
Original
1681 people have browsed it

public function index()

<code>{    

    $timeStamp    ="";
    $nonce        ="";
    $encrypt_type ='';
    $msg_sign     ='';
    $encryptMsg   =file_get_contents('php://input');
    
    $result = $this->getVerify_Ticket($timeStamp,$nonce,$encrypt_type,$msg_sign,$encryptMsg);

    if($result){
        echo "success";
    }

}
</code>
Copy after login
Copy after login

//Get component_verify_ticket

<code>public function getVerify_Ticket($timeStamp,$nonce,$encrypt_type,$msg_sign,$encryptMsg){

    $pc = new WXBizMsgCrypt(WxPayConfig::Token, WxPayConfig::EncodingAesKey, WxPayConfig::open_AppID);

    $xml_tree = new \DOMDocument();
    $xml_tree->loadXML($encryptMsg);
    $array_e = $xml_tree->getElementsByTagName('Encrypt');
    $encrypt = $array_e->item(0)->nodeValue;

    $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";

    $from_xml = sprintf($format, $encrypt);

    $msg = '';

    $errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);

    if ($errCode == 0) {

        $xml = new \DOMDocument();
        $xml->loadXML($msg);
        $array_e = $xml->getElementsByTagName('ComponentVerifyTicket');

        $component_verify_ticket = $array_e->item(0)->nodeValue;
        DB::getDB()->delete("wechat_verifyticket",'uptime!=1');
        DB::getDB()->insert("wechat_verifyticket",array(
            'component_verify_ticket'    => $component_verify_ticket,
            'uptime'                    => time()));

        return true;
    }else{
        DB::getDB()->delete("wechat_verifyticket",'uptime!=1');
        DB::getDB()->insert("wechat_verifyticket",array(
            'component_verify_ticket'    => $errCode,
            'uptime'                    => time()));
        return false;
    }

} </code>
Copy after login
Copy after login

Reply content:

public function index()

<code>{    

    $timeStamp    ="";
    $nonce        ="";
    $encrypt_type ='';
    $msg_sign     ='';
    $encryptMsg   =file_get_contents('php://input');
    
    $result = $this->getVerify_Ticket($timeStamp,$nonce,$encrypt_type,$msg_sign,$encryptMsg);

    if($result){
        echo "success";
    }

}
</code>
Copy after login
Copy after login

//Get component_verify_ticket

<code>public function getVerify_Ticket($timeStamp,$nonce,$encrypt_type,$msg_sign,$encryptMsg){

    $pc = new WXBizMsgCrypt(WxPayConfig::Token, WxPayConfig::EncodingAesKey, WxPayConfig::open_AppID);

    $xml_tree = new \DOMDocument();
    $xml_tree->loadXML($encryptMsg);
    $array_e = $xml_tree->getElementsByTagName('Encrypt');
    $encrypt = $array_e->item(0)->nodeValue;

    $format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";

    $from_xml = sprintf($format, $encrypt);

    $msg = '';

    $errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);

    if ($errCode == 0) {

        $xml = new \DOMDocument();
        $xml->loadXML($msg);
        $array_e = $xml->getElementsByTagName('ComponentVerifyTicket');

        $component_verify_ticket = $array_e->item(0)->nodeValue;
        DB::getDB()->delete("wechat_verifyticket",'uptime!=1');
        DB::getDB()->insert("wechat_verifyticket",array(
            'component_verify_ticket'    => $component_verify_ticket,
            'uptime'                    => time()));

        return true;
    }else{
        DB::getDB()->delete("wechat_verifyticket",'uptime!=1');
        DB::getDB()->insert("wechat_verifyticket",array(
            'component_verify_ticket'    => $errCode,
            'uptime'                    => time()));
        return false;
    }

} </code>
Copy after login
Copy after login

What is the error message?

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template