微信第三方平台全网发布检测

  • 首先感谢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给好好整整啊,完全不会用

转载于:https://my.oschina.net/nixus/blog/1620988

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值