承接 lijinhua/hyperf-wechat 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lijinhua/hyperf-wechat

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lijinhua/hyperf-wechat

包简介

适用于hyperf的微信sdk

README 文档

README

微信 SDK for Hyperf, 基于 w7corp/easywechat

由于 easywechat v6 使用了 symfony/http-client作为请求库,hyperf提供了ClassMap替换能力,此包替换EasyWechat底层InteractWithHttpClient中的HttpClient对象实例,支持协程。

安装

composer require lijinhua/hyperf-wechat

配置

  1. 发布配置文件
php ./bin/hyperf.php vendor:publish lijinhua/hyperf-wechat
  1. 修改根目录下的 config/autoload/wechat.php 中对应的参数即可。
  2. 每个模块都支持多账号,默认为 default

使用

接收普通消息例子:

Router::addRoute(['GET', 'POST', 'HEAD'], '/wechat', 'App\Controller\WeChatController@serve');

注意:微信服务端认证的时候是 GET, 接收用户消息时是 POST

<?php
declare(strict_types=1);

namespace App\Controller;

use EasyWeChat\Kernel\Exceptions\BadRequestException;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use Lijinhua\HyperfWechat\EasyWechat;
use Lijinhua\HyperfWechat\Helper;
use ReflectionException;

class WeChatController
{
    /**
     * 处理微信的请求消息
     *
     * @return string
     * @throws BadRequestException
     * @throws InvalidArgumentException
     * @throws InvalidConfigException
     * @throws ReflectionException
     */
    public function serve()
    {
        $app = EasyWechat::officialAccount();
        $server = $app->getServer();
        
        $server->with(function ($message, \Closure $next) {
            return '谢谢关注!';
            
            // 自定义逻辑
            // return $next($message);
        });
        
        // 一定要用Helper::Response去转换
        return Helper::Response($server->serve());
    }
}
EasyWechat中已对request及cache对象替换,更方便使用
  use Lijinhua\HyperfWechat\EasyWechat;
  
  $officialAccount = EasyWechat::officialAccount(); //公众号
  $pay = EasyWechat::pay(); //微信支付
  $miniApp = EasyWechat::miniApp(); //小程序
  $openPlatform = EasyWechat::openPlatform(); //开放平台
  $work = EasyWechat::work(); //企业微信
  $openWork = EasyWechat::openWork(); //企业微信开放平台
  
  // `foo` 为配置文件中的名称,默认为 `default`。`[]` 可覆盖账号配置
  EasyWeChat::officialAccount('foo', []);

更多详细的用法,请参考:https://easywechat.com

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-08