第三方平台全网发布API验证

<?php
include_once "wxBizMsgCrypt.php";
//encodingAesKey和token均为申请三方平台是所填写的内容
$encodingAesKey = '';
$token = '';
$appId = '';

$timeStamp  = empty($_GET['timestamp'])     ? ""    : trim($_GET['timestamp']) ;

$nonce      = empty($_GET['nonce'])         ? ""    : trim($_GET['nonce']) ;

$msg_sign   = empty($_GET['msg_signature']) ? ""    : trim($_GET['msg_signature']);

$app_id = $_GET['appid'];

$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
//获取到微信推送过来post数据(xml格式)
$postArr = file_get_contents("php://input");

$msg = '';

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

    $postObj=simplexml_load_string($msg,'SimpleXMLElement',LIBXML_NOCDATA);

//第三方平台全网发布检测返回api文本消息测试
    if(strpos ($postObj->Content, 'QUERY_AUTH_CODE' ) !== false){
        $query_auth_code= str_replace ( 'QUERY_AUTH_CODE:', '', $postObj->Content);
        $info= getAuthInfo($query_auth_code);

        file_put_contents('lo.txt', '['.date('Y-m-d : h:i:sa',time()).']'.$query_auth_code.'00'.json_encode($info)."\n\r",FILE_APPEND);

        $access_info=$info['authorization_info']['authorizer_access_token'];
        $param =array();
        $param['touser'] = "$postObj->FromUserName";
        $param['msgtype'] = 'text';
        $param['text']['content'] = $query_auth_code.'_from_api';

        $url='https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$access_info;
        $test = post_data($url,json_encode($param));
        file_put_contents('lo.txt', '['.date('Y-m-d : h:i:sa',time()).']'.$query_auth_code.'12'.json_encode($param)."\n\r",FILE_APPEND);
        file_put_contents('lo.txt', '['.date('Y-m-d : h:i:sa',time()).']'.$query_auth_code.'11'.json_encode($test)."\n\r",FILE_APPEND);
    }


function responseText($postObj,$content){

    $xml = "<xml>";

    $xml.= "<ToUserName><![CDATA[".$postObj->FromUserName."]]></ToUserName>";

    $xml.= "<FromUserName><![CDATA[".$postObj->ToUserName."]]></FromUserName>";

    $xml.= "<CreateTime>".time()."</CreateTime>";
    $xml.= "<MsgType><![CDATA[text]]></MsgType>";

    $xml.= "<Content><![CDATA[".$content."]]></Content>";

    $xml.= "</xml>";

    return $xml;

}

function post_data($url,$postdata){

    $ch = curl_init(); //用curl发送数据给api
    // curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $postdata );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE );
    $response = curl_exec($ch);
    curl_close( $ch );
    $rest = json_decode($response,true);
    return $rest;
}

function getAuthInfo($query_auth_code){

    $access_token = '';
    $urlAuth = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=$access_token";
    $postdata = array(
        'component_appid' =>'',
        'authorization_code' =>$query_auth_code,
    );
    $postdata = json_encode($postdata);

    $resultAuth = post_data($urlAuth,$postdata);
    return $resultAuth;

}

echo $test;

exit();
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值