微信第三方授权全网发布检测代码

微信回调处理关键这3步通过基本没问题

function checkMsgDecode($timeStamp,$nonce,$encrypt_type,$msg_sign,$encryptMsg){
    $pc = new WXBizMsgCrypt($this->token, $this->encodingAesKey, $this->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);
    $xml = new DOMDocument();
    $xml->loadXML($msg);

    $Content = $xml->getElementsByTagName('Content')->item(0)->nodeValue;
    $FromUserName = $xml->getElementsByTagName('FromUserName')->item(0)->nodeValue;

    file_put_contents('msg.txt', '8'.$Content,FILE_APPEND);
    if( strstr($Content,'QUERY_AUTH_CODE') ){
        file_put_contents('QUERY_AUTH_CODE.txt', $Content);

        $auth_code = str_replace('QUERY_AUTH_CODE:','',$Content);
        $access_token = self::getComponentAccessToken();

        $post_url = $this->authorizer_access_token_url.$access_token;
        $post_data = array(
            'component_appid'=>$this->appId,
            'authorization_code'=>$auth_code
        );
        $post_data = json_encode($post_data);
        $return_data = $this->curl($post_url,$post_data,'POST');
        $data_dejson = $this->doJson($return_data);
        $authorizer_access_token = $data_dejson['authorization_info']['authorizer_access_token'];
        $this->cache->Add('check_authorizer_access_token',$authorizer_access_token,7000);
        file_put_contents('authorizer_access_token.txt',$authorizer_access_token);

        $post_url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$authorizer_access_token;
        $new_Content =  $auth_code. '_from_api';

        //$res = json_decode(self::https_request($new_url,$new_Content));

        $post_data = array(
            "touser" => $FromUserName,
            "msgtype" => "text",
            "text" => array("content"=>$new_Content)
        );
        $post_data = json_encode($post_data);
        $return_data = $this->curl($post_url,$post_data,'POST');
        //$data_dejson = $this->doJson($return_data);
        file_put_contents('touser.txt',$return_data);
        file_put_contents('return_data.txt',$return_data);
        file_put_contents('new_url.txt',$post_url);
        file_put_contents('new_Content.txt',$new_Content);
        return  true;

    }



    if( strstr($Content,'TESTCOMPONENT_MSG_TYPE_TEXT') ){
        /*
            file_put_contents('msg2.txt', $msg);
             $xml_format = $this->xmlFormat($msg,'TESTCOMPONENT_MSG_TYPE_TEXT_callback');
              file_put_contents('msg22.txt', $xml_format);
              $res = $this->msgEncode($timeStamp,$nonce,$xml_format);
                 file_put_contents('msg222.txt', $res);
        */

        $authorizer_access_token = $this->cache->Get('check_authorizer_access_token');
        $post_url2="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$authorizer_access_token;
        $post_data2 = array(
            "touser" => $FromUserName,
            "msgtype" => "text",
            "text" => array("content"=>"TESTCOMPONENT_MSG_TYPE_TEXT_callback")
        );
        $post_data2 = json_encode($post_data2);
        file_put_contents('post_data.txt',$post_data2);

        $return_data = $this->curl($post_url2,$post_data2,'POST');
        file_put_contents('return_data2.txt',$return_data);

        return '';

    }


    $Event = $xml->getElementsByTagName('Event')->item(0)->nodeValue;
    if( isset($Event) ){
        file_put_contents('ori_msg.txt', $msg);

        $authorizer_access_token = $this->cache->Get('check_authorizer_access_token');
        $post_url="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$authorizer_access_token;
        $post_data = array(
            "touser" => $FromUserName,
            "msgtype" => "text",
            "text" => array("content"=>$Event.'from_callback')
        );
        $post_data = json_encode($post_data);
        $return_data = $this->curl($post_url,$post_data,'POST');
        file_put_contents('return_data3.txt',$return_data);


        return $return_data;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值