-
首先感谢easyWechat的作者,提供了非常实用的SDK!
-
其次感谢飞山雪豹,虽然看了这个帖子后,还是走了很多弯路(自己太蠢),但是,没有这个帖子,只看微信文档,完全没有头绪;
-
最后,问候微信文档的作者!!!
-
微信全网发布检测的文档,看了几遍,可能是懵逼(Fuck The Writer Of The WeChat Document)的状态下,完全不知道文档在说什么……
-
解决步骤:
-
首先微信会验证
返回Api文本消息
这一项,在验证这项的时候,会有授权的code,可以拿到授权信息,需要保存下来,在验证返回普通文本消息
和发送事件消息
的时候,都会用到,感觉这个比较关键; -
自己根据飞山雪豹帖子中的代码,做了一些调整,最终在凌晨2:30,终于被微信全网发布检测通过了。
// 由于项目使用的框架是laravel,所以以下代码都是基于laravel的
// http://www.example.com/Receiver/$APPID$
// $app_id 是微信传过来的公众号或小程序的APPID
// $this->openPlatform = \EasyWeChat::openPlatform(); 这行写在了构造函数里了
// 路由:
Route::any('Receiver/{appid}', '控制器@方法'); // 接收微信推送来的事件和消息
public function receiver($app_id)
{
$this->app_id = $app_id;
// $official = $this->initOfficialAccount();
$openPlatform = $this->openPlatform;
$server = $openPlatform->server;
$server->push(EventHandler::class, Message::EVENT); // 检测中,这个是没什么用的
$msg = $server->getMessage();
if ($msg['MsgType'] == 'text') {
if ($msg['Content'] == 'TESTCOMPONENT_MSG_TYPE_TEXT') {
$curOfficialAccount = $openPlatform->officialAccount($app_id, Redis::get($app_id));
$curOfficialAccount->customer_service->message($msg['Content'] . '_callback')
->from($msg['ToUserName'])->to($msg['FromUserName'])->send();
die;
} elseif (strpos($msg['Content'], 'QUERY_AUTH_CODE') == 0) {
echo '';
$code = substr($msg['Content'], 16);
$authorizerInfo = $openPlatform->handleAuthorize($code)['authorization_info'];
Redis::set(
$authorizerInfo['authorizer_appid'],
$authorizerInfo['authorizer_refresh_token']
);
Redis::expire($authorizerInfo['authorizer_appid'], 20);
$curOfficialAccount = $openPlatform->officialAccount(
$authorizerInfo['authorizer_appid'],
$authorizerInfo['authorizer_refresh_token']
);
$curOfficialAccount->customer_service->message($code . "_from_api")
->from($msg['ToUserName'])->to($msg['FromUserName'])->send();
}
} elseif ($msg['MsgType'] == 'event') {
$curOfficialAccount = $openPlatform->officialAccount($app_id, Redis::get($app_id));
$curOfficialAccount->customer_service->message($msg['Event'] . 'from_callback')
->to($msg['FromUserName'])->from($msg['ToUserName'])->send();
die;
}
return $openPlatform->server->serve();
}
代码尚有优化的空间,但是在检测的时候,完全可以跑通
再次感谢easyWechat提供了非常实用的SDK!
话说,OSC啥时候能把这个md给好好整整啊,完全不会用