>  기사  >  백엔드 개발  >  微信第三方登录 - php获取component_verify_ticket?

微信第三方登录 - php获取component_verify_ticket?

WBOY
WBOY원래의
2016-08-04 09:19:391516검색

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>

//获取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></tousername><encrypt></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>

回复内容:

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>

//获取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></tousername><encrypt></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>

出错提示是什么?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.