{"id":26879927,"url":"https://github.com/qiqizjl/think-wechat","last_synced_at":"2025-04-07T14:11:18.401Z","repository":{"id":57023511,"uuid":"134600991","full_name":"qiqizjl/think-wechat","owner":"qiqizjl","description":"easywechat for thinkphp support","archived":false,"fork":false,"pushed_at":"2021-08-08T18:36:25.000Z","size":40,"stargazers_count":267,"open_issues_count":5,"forks_count":63,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-27T07:13:23.580Z","etag":null,"topics":["easywechat","think","thinkphp","wechat","weixin"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qiqizjl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-23T17:01:27.000Z","updated_at":"2025-01-19T08:22:54.000Z","dependencies_parsed_at":"2022-08-22T12:00:25.464Z","dependency_job_id":null,"html_url":"https://github.com/qiqizjl/think-wechat","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqizjl%2Fthink-wechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqizjl%2Fthink-wechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqizjl%2Fthink-wechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qiqizjl%2Fthink-wechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qiqizjl","download_url":"https://codeload.github.com/qiqizjl/think-wechat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666008,"owners_count":20975787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easywechat","think","thinkphp","wechat","weixin"],"created_at":"2025-03-31T13:33:36.225Z","updated_at":"2025-04-07T14:11:18.377Z","avatar_url":"https://github.com/qiqizjl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# thinkphp-wechat\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fqiqizjl%2Fthink-wechat.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fqiqizjl%2Fthink-wechat?ref=badge_shield)\n\n微信SDK For ThinkPHP 5.1 基于[overtrue/wechat](https://github.com/overtrue/wechat)\n\n## 框架要求\nThinkPHP5.1(中间件要求支持ThinkPHP5.1.6+)\n\n## 安装\n~~~\ncomposer require naixiaoxin/think-wechat \n~~~\n\n## 配置\n1. 修改配置文件\n修改项目根目录下config/wechat.php中对应的参数\n\n2. 每个模块基本都支持多账号，默认为 default。\n  \n\n## 使用\n### 接受普通消息\n新建一个Controller，我这边用的是Note\n```php\n\u003c?php\n\nnamespace app\\wechat\\controller;\n\n\nuse think\\Controller;\n\nclass Note extends Controller\n{\n\n    public function index()\n    {\n        //    先初始化微信\n        $app = app('wechat.official_account');\n        $app-\u003eserver-\u003epush(function($message){\n            return 'hello,world';\n        });\n        $app-\u003eserver-\u003eserve()-\u003esend();\n    }\n}\n```\n### 获得SDK实例\n#### 使用facade\n```php\nuse Naixiaoxin\\ThinkWechat\\Facade;\n\n$officialAccount = Facade::officialAccount();  // 公众号\n$work = Facade::work(); // 企业微信\n$payment = Facade::payment(); // 微信支付\n$openPlatform = Facade::openPlatform(); // 开放平台\n$miniProgram = Facade::miniProgram(); // 小程序  \n$openWork = Facade::openWork(); // 企业微信第三方服务商  \n$microMerchant = Facade::microMerchant(); // 小微商户  \n```\n以上均支持传入自定义账号:例如\n```php\n$officialAccount = Facade::officialAccount('test'); // 公众号\n```\n\n以上均支持传入自定义账号+配置(注:这里的config和配置文件中账号的格式相同):例如\n```php\n$officialAccount = Facade::officialAccount('',$config); // 公众号\n```\n\n### Oauth登录中间件(ThinkPHP5.1.6+)\n使用中间件情况下，config的oauth.callback可以随便写~，反正是直接获取了当前URL\n```php\n\\think\\facade\\Route::rule('user','usere')-\u003emiddleware(\\Naixiaoxin\\ThinkWechat\\Middleware\\OauthMiddleware::class);\n```\n\n上面的路由定义了 /user 是需要微信授权的，那么在这条路由的回调 或 控制器对应的方法里， 你就可以从 session('wechat_oauth_user_default') 拿到已经授权的用户信息了。\n\n\n关于ThinkPHP5.1的中间件使用方法不在叙述，详情可以查看[官方文档](https://www.kancloud.cn/manual/thinkphp5_1/564279)\n\n#### 中间件参数说明\n由于ThinkPHP中间件只支持一个参数，所以以`:`做分割\n\n支持传入account账号别名以及scope类型\n\n若不传入`account`，会使用`default`账号\n\n若不传入`scope`，会使用配置文件中的`oauth.scope`\n\n支持一下两种方式\n```\ndefault:snsapi_base\nsnsapi_base\n```\n\n### HOOK\n\u003e 你可以监听相应的事件，并对事件发生后执行相应的操作。\n- OAuth授权 `wechat_oauth`\n\n```php\n// 该事件有以下属性\n$params['user']; // 同 session('wechat_oauth_user_default') 一样\n$params['is_new']; // 是不是新的会话（第一次创建 session 时为 true）\n```\n更多 SDK 的具体使用请参考：https://easywechat.com\n\n## 参考项目\n- [overtrue/laravel-wechat](https://raw.githubusercontent.com/overtrue/laravel-wechat)\n\n## License\n\nMIT\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fqiqizjl%2Fthink-wechat.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fqiqizjl%2Fthink-wechat?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqizjl%2Fthink-wechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqiqizjl%2Fthink-wechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqiqizjl%2Fthink-wechat/lists"}