2018-03-28 16:13:24 1737次浏览 0条回答 0 悬赏 50 金钱

用的max-wen/yii2-easy-wechat,微信后台配置能走通,说明服务端api没有问题:
路由为http://t.lechangame.com/weixin/api?id=1,
如下全部写在构造函数里面就可以实现通信成功(关键词回复)。
构造删掉,写到actionApi方法里就有问题,请问怎么排错?
好多人说写到beforeAction里面,写到这里面也不行啊

class WeixinController extends Controller
{
    public $wechat;
    public $app;

    public function __construct($id,  $module, array $config = [])
    {
        parent::__construct($id, $module, $config);

        $this->wechat = Yii::$app->wechat;

        \Yii::warning("请求成功111", 'weixin');

        $id = Yii::$app->request->get('id');
        
        $account = WechatAccount::findOne($id);

        Yii::$app->params['WECHAT'] = [
            'debug'  => true,
            'app_id' => $account->appid,
            'secret' => $account->appsecret,
            'token'  => $account->token,
            'log' => [
                'level' => 'debug',
                'file'  => '../runtime/logs/easywechat.log',
            ],
        ];

        $this->app = $this->wechat->getApp();

        $server = $this->app->server;

        $server->setMessageHandler(function ($message) {
            \Yii::warning($message, 'weixin');

            return "您好!欢迎关注我!";
        });

        $response = $server->serve();
        $response->send();

    }



    public function actionApi()
    {

    }
补充于 2018-03-28 16:15

写到api方法里面就有问题,在api方法入口记录日志都没有,说明根本没有进这个方法。

补充于 2018-03-28 16:44

问题已解决,需要关闭csrf

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
王文凡
经理

王文凡 ChengDu

注册时间:2016-04-11
最后登录:2018-07-26
在线时长:20小时44分
  • 粉丝3
  • 金钱1065
  • 威望10
  • 积分1365

热门问题