overtrue/wechat 怎么对接微信 对话服务

hongshao

对文档的代码调整了下,但没办法打印sendl输出内容,难道要采用ob?

<?php

namespace app\controller;
use support\Request;
use EasyWeChat\Factory;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;

use app\BaseController;

class Wechat extends BaseController
{
    public function index(Request $request)
    {
        $config = [
            'app_id' => '',
            'secret' => '',
            'token' => '',
            'response_type' => 'array',
        ];

        $app = Factory::officialAccount($config);

        $symfony_request = new SymfonyRequest($request->get(), $request->post(), [], $request->cookie(), [], [], $request->rawBody());
        $symfony_request->headers = new HeaderBag($request->header());
        $app->rebind('request', $symfony_request);

        $app->server->push(function ($message) {
            return "您好!欢迎关注";
        });

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

        return $response->send()->getContent();
      }

}
1238 2 2
2个回答

admin

我做过这个,我记得不是ob,晚上找一下项目

  • hongshao 2022-07-18

    return xml($response->getContent());
    目前是这样写的,解决是解决了,但wechat不熟,慢慢研究

admin
  $openPlatform->server->push(function ($msg){
            if(!isset($msg['status']) || strval($msg['status'])!='0'){
                //失败
            }
            //成功
        },Guard::EVENT_THIRD_FAST_REGISTERED);

        $openPlatform->server->push(function ($msg){
//            var_dump($msg);
        },Guard::EVENT_COMPONENT_VERIFY_TICKET);
        $response = $openPlatform->server->serve();
        return $response->getContent();
年代过于久远,无法发表回答
×
🔝