微信第三方全网发布接入检测(PHP)
官方文档 https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318292&token=&lang=zh_CN
function getTicket(){
$data = input('param.');
trace($data,'data');
$msg_sign = input('msg_signature');
$timeStamp = input('timestamp');
$nonce = input('nonce'); $encryptMsg = file_get_contents ( 'php://input' );
trace($encryptMsg,'getTicket'); //因为数据格式,先加密再解密 $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; echo 'success'; $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);
trace($msg,"msg: " );
if ($errCode == 0) {
//print("解密后: " . $msg . "\n");
$xml = new \DOMDocument();
$xml->loadXML($msg);
$array_e = $xml->getElementsByTagName('ComponentVerifyTicket');
//保存下来
$this->component_verify_ticket = $array_e->item(0)->nodeValue; //获取保存accessToken
$this->component_access_token = $this->component->getComponentToken($this->component_verify_ticket); } else {
print($errCode . "\n");
} } //全网发布响应
function callback(){
$appid = input('appid');
$msg_sign = input('msg_signature');
$timeStamp = input('timestamp');
$nonce = input('nonce'); $encryptMsg = file_get_contents ( 'php://input' ); trace($encryptMsg,'php://inpu'); //解密
$pc = new WXBizMsgCrypt($this->token, $this->encodingAesKey, $this->appid);
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $encryptMsg, $msg); trace($msg,"3解密后: " );
$response = json_decode(json_encode(simplexml_load_string($msg, 'SimpleXMLElement', LIBXML_NOCDATA)), true); //生成返回公众号的消息
$res_msg = $textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
</xml>"; //判断事件 //2模拟粉丝发送文本消息给专用测试公众号 if ($response['MsgType']=="text") {
$needle ='QUERY_AUTH_CODE:';
$tmparray = explode($needle,$response['Content']);
if(count($tmparray)>1){
trace($response,"解密后: " );
//3、模拟粉丝发送文本消息给专用测试公众号,第三方平台方需在5秒内返回空串
//表明暂时不回复,然后再立即使用客服消息接口发送消息回复粉丝
$contentx = str_replace ($needle,'',$response['Content']);//将$query_auth_code$的值赋值给API所需的参数authorization_code
$this->authorization_code = $contentx;//authorization_code
trace($contentx,'authorization_code'); //使用授权码换取公众号或小程序的接口调用凭据和授权信息
$postdata = array(
"component_appid"=>$this->appid,
"authorization_code"=>$this->authorization_code,
); $this->component_access_token = $this->component->getAccessToken(); trace($this->component_access_token,'access_token'); $component_return = send_post($this->authorizer_access_token_url.$this->component_access_token,$postdata); $component_return = json_decode($component_return,true);
trace($component_return,'$component_return');
$this->authorizer_access_token = $test_token = $component_return['authorization_info']['authorizer_access_token'];
$content_re = $contentx."_from_api";
echo ''; //調用客服接口 $data = array(
"touser"=>$response['FromUserName'],
"msgtype"=>"text",
"text" => array(
"content" =>$content_re
)
);
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$test_token;
$ret = send_post($url, $data);
trace($ret,'客服消息'); } else{
//2、模拟粉丝发送文本消息给专用测试公众号
$contentx = "TESTCOMPONENT_MSG_TYPE_TEXT_callback"; trace($response,"2模拟粉丝发送文本消息给专用测试公众号: " );
$responseText = sprintf( $textTpl, $response[ 'FromUserName' ], $response[ 'ToUserName' ], $response[ 'CreateTime' ], $contentx );
// echo $responseText;
$echo_msg='';
$errCode = $pc->encryptMsg($responseText, $timeStamp, $nonce, $echo_msg);
trace($responseText,"2222转数组: " );
echo $echo_msg;
}
} //1、模拟粉丝触发专用测试公众号的事件 if ($response['MsgType'] == 'event'){
$content = $response['Event']."from_callback"; trace($response,"111转数组: " );
$responseText = sprintf( $textTpl, $response[ 'FromUserName' ], $response[ 'ToUserName' ], $response[ 'CreateTime' ], $content );
trace($responseText,"111: " );
// echo $responseText;
$errCode = $pc->encryptMsg($responseText, $timeStamp, $nonce, $echo_msg); echo $echo_msg;
} }
微信第三方全网发布接入检测(PHP)的更多相关文章
- 微信开放平台开发-授权、全网发布(PHP)
这两天做了微信开发平台的开发,梳理下... 浙江百牛信息技术bainiu.ltd整理发布于博客园 先看看授权的流程: 第一步:接收component_verify_ticket: 1.微信服务器每隔1 ...
- 微信支付v2开发(10) 全网发布
关键字:微信公众平台 微信支付 全网发布 作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/p/wxpay-publish.html 在这篇微信公众平台开发教程中, ...
- 微信开放平台全网发布时,检测失败 —— C#
主要就是三个:返回API文本消息,返回普通文本消息,发送事件消息 --会出现失败的情况 (后续补充说明:出现检测出错,不一定是代码出现了问题,也有可能是1.微信方面检测时出现服务器请求失败,2.我 ...
- 微信公众账号第三方平台全网发布源码(java)- 实战测试通过
第一部分:微信第三方平台配置
- 海洋cms自带资源发布api插件和第三方资源站接入办法说明
海洋cms自带资源发布api插件和第三方资源站接入办法说明 时间:2016-07-15 13:46 来源:CMS模版网 作者:大宇 阅读:7095次 ===海洋cms自带API资源发布插件说明===* ...
- iOS微信第三方登录实现
iOS微信第三方登录实现 一.接入微信第三方登录准备工作.移动应用微信登录是基于OAuth2.0协议标准构建的微信OAuth2.0授权登录系统.在进行微信OAuth2.0授权登录接入之前,在微信开 ...
- laravel5实现微信第三方登录功能
背景 最近手头一个项目需要实现用户在网站的第三方登录(微信和微博),后端框架laravel5.4. 实现过程以微信网页版第三方登录,其他于此类似,在此不做重复. 准备工作 网站应用微信登录是基于OAu ...
- Android Learning:微信第三方登录
这两天,解决了微信第三方授权登录的问题,作为一个新手,想想也是一把辛酸泪.我想着,就把我的遇到的坑给大家分享一下,避免新手遇到我这样的问题能够顺利避开. 步骤一 微信开发者平台 我开始的解决思路是,去 ...
- 如何让微信小程序快速接入七牛云
如果你确定用七牛运行小程序的话,给大家分享一个九折优惠码:61d1fd4d1 月 9 日 微信小程序正式发布,小程序终于揭开了它神秘的面纱,开发者对小程序的追捧更是热度不减.从小程序的热门应用场景来看 ...
随机推荐
- 【ANT】taskdef class org.programmerplanet.ant.taskdefs.jmeter.JMeterTask cannot be found using the classloader AntClassLoader[]解决办法
把文件apache-jmeter-3.1\extras\ant-jmeter-1.1.1.jar复制到apache-ant-1.10.1\lib目录下即可.
- Charles 抓包工具使用部分问题总结
一. You may need to configure your browser or application to trust the Charles Root Certificate. See ...
- Base64转换二进制文件对象 Blob/Base64转换 File 对象
function convertBase64UrlToBlob(urlData) { var arr = dataurl.split(','),//去掉url的头,并转换为byte type = ar ...
- iOS自定义文字高度添加行间距
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 } span.s1 { } span.s2 { c ...
- JDK 1.8 源码阅读和理解
根据 一篇文章教会你,如何做到招聘要求中的“要有扎实的Java基础” 的指引,决定开始阅读下JDK源码. 本文将作为源码阅读总纲 一.精读部分 java.io java.lang java.util ...
- [array] leetcode - 54. Spiral Matrix - Medium
leetcode-54. Spiral Matrix - Medium descrition GGiven a matrix of m x n elements (m rows, n columns) ...
- qt关键字高亮
qt的高亮显示主要是使用qsyntaxhighlighter类,由于qsyntaxhighlighter是抽象基类,所以需要继承并自己实现 //头文件 #ifndef MARKDOWN_HIGHLIG ...
- linux下制作镜像文件
第一:制作iso镜像的方法: 把/dev/cdrom目录制作为镜像,名字为/root/rh1.iso 方法1:dd if=/dev/cdrom of=/root/rh1.iso 方法2:#cat /d ...
- DNS 域名系统的简介
一.DNS域名系统简介 1.网络中为了区别各个主机,必须为每台主机分配一个唯一的地址, 这个地址即称为“IP 地址.但这些数字难以记忆, 所以采用“域名” 的方式来取代这些数字. 2.当某台主机要与其 ...
- Unix 文件系统读写时权限校验
文件系统中的所有文件都是在读出或写入时进行权限校验 一个问题,如果一个用户对一个普通文件有读写权限,在使用vim编辑时,管理员撤销掉此用户对此文件的写入权限 那么,这个普通用户还可以将修改写入文件吗?