weixin_39713317
2021-01-08 12:35 阅读 47

`overtrue/wechat` 包微信开放平台接收请求验证票据固定唯一问题

  1. Your software version (Screenshot of your startup)

    | Software | Version | | --------- | --------- | | PHP | 7.3.6 NTS | | Swoole | 4.4.12 | | Laravel | 5.8 |

  2. Detail description about this issue(error/log)

使用 overtrue/wechat 包开发微信第三方开放平台,用来接收验证票据的接口会一直使用第一次数据,如何在 cleaners 中增加清理呢?目前使用下面的办法解决的,但是发现有很多 ServiceProvider 类,都需要一一添加吗?


// 用于清理注册了单例的 ServiceProvider
    'register_providers'       => [
        Overtrue\LaravelWeChat\ServiceProvider::class,
    ],
  1. Some reproducible code blocks and steps

① 开启 wechat.php 配置项的 route 注释的路由代码


  /*
     * 路由配置
     */
    'route' => [
        /*
         * 开放平台第三方平台路由配置
         * 配置后 http://example.com/open-platform/serve 则为开放平台第三方应用设置的授权事件接收 URL
         */
        'open_platform' => [
            'uri' => 'serve',
            'action' => Overtrue\LaravelWeChat\Controllers\OpenPlatformController::class,
            'attributes' => [
                'prefix' => 'open-platform',
                'middleware' => null,
            ],
        ],
    ],

② 模拟 POST 请求,请求地址 : http://127.0.0.1:5200/open-platform/serve?encrypt_type=aes&msg_signature=5209bb506be412eab6013fdf89213bd37f9d3479&nonce=991710142&signature=4e01a46e5db49206606391f2de9d91360294077b&timestamp=1587609878

wechat.log 日志

PHP
[2020-04-27 17:48:03] EasyWeChat.DEBUG: Request received: {"method":"POST","uri":"http://127.0.0.1:5200/open-platform/serve?encrypt_type=aes&msg_signature=5209bb506be412eab6013fdf89213bd37f9d3479&nonce=991710142&signature=4e01a46e5db49206606391f2de9d91360294077b&timestamp=1587609878","content-type":null,"content":"{\"type\":\"object\",\"title\":\"empty object\",\"properties\":{}}"} []
[2020-04-27 17:48:03] EasyWeChat.DEBUG: Server response created: {"content":"success"} []

该提问来源于开源项目:hhxsv5/laravel-s

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • weixin_39631519 weixin_39631519 2021-01-08 12:35

    185

    点赞 评论 复制链接分享
  • weixin_39713317 weixin_39713317 2021-01-08 12:35

    easywechat 读取的是php://input,但Swoole下这个输入流无效,参考已知问题

    
    $app['request'] = $request;//在原有代码添加这一行,将当前Request赋值给$app['request']
    

    赋值 $request 对象给easywechat。 那我需要到 vendor/overtrue/laravel-wechat/src/ServiceProvider.php,在 register() 方法里面注入吗?

    
        /**
         * Register the provider.
         */
        public function register()
        {
            $this->setupConfig();
    
            $apps = [
                'official_account' => OfficialAccount::class,
                'work' => Work::class,
                'mini_program' => MiniProgram::class,
                'payment' => Payment::class,
                'open_platform' => OpenPlatform::class,
                'open_work' => OpenWork::class,
            ];
          // 在此处增加代码?
        }
    

    而且如果这么处理,和清理注册了单例的 ServiceProvider 也没有啥区别呀,都需要每个注册单独写代码。

    
    // 用于清理注册了单例的 ServiceProvider
        'register_providers'       => [
            Overtrue\LaravelWeChat\ServiceProvider::class,
        ],
    
    点赞 评论 复制链接分享
  • weixin_39631519 weixin_39631519 2021-01-08 12:35

    不需要清理ServiceProvider,只需要在用到easywechat的app之前赋值$request

    点赞 评论 复制链接分享

相关推荐