{"id":20355507,"url":"https://github.com/honlan/omnilab-wechat","last_synced_at":"2025-10-29T23:02:48.482Z","repository":{"id":21266291,"uuid":"24581971","full_name":"Honlan/omnilab-wechat","owner":"Honlan","description":"this is the wechat repository for OMNILab","archived":false,"fork":false,"pushed_at":"2014-10-14T04:50:21.000Z","size":1420,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T01:55:49.087Z","etag":null,"topics":[],"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/Honlan.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":"2014-09-29T06:06:09.000Z","updated_at":"2015-05-22T07:42:14.000Z","dependencies_parsed_at":"2022-09-12T10:21:00.721Z","dependency_job_id":null,"html_url":"https://github.com/Honlan/omnilab-wechat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Honlan/omnilab-wechat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Honlan%2Fomnilab-wechat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Honlan%2Fomnilab-wechat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Honlan%2Fomnilab-wechat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Honlan%2Fomnilab-wechat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Honlan","download_url":"https://codeload.github.com/Honlan/omnilab-wechat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Honlan%2Fomnilab-wechat/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260536088,"owners_count":23024298,"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":[],"created_at":"2024-11-14T23:13:05.756Z","updated_at":"2025-10-29T23:02:48.471Z","avatar_url":"https://github.com/Honlan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"微信公众平台 PHP SDK\r\n=====\r\n\r\n介绍\r\n-----\r\n简单的微信公众平台 PHP SDK ，通过调用相应的接口，使你可以轻松地开发微信 App 。测试方法如下：\r\n\r\n  1. Clone 或下载项目源码，上传至服务器。\r\n\r\n  2. 进入[微信公众平台](https://mp.weixin.qq.com/)，高级功能，开启开发模式，并设置接口配置信息。修改 `URL` 为 `/example/server.php` 的实际位置，修改 `Token` 为 `weixin` （可自行在 `/example/server.php` 中更改）。\r\n\r\n  3. 向你的微信公众号发送消息并测试吧！\r\n\r\n用法\r\n-----\r\n\r\n直接浏览 `/example/server.php` 了解基本用法，以下为详细说明。\r\n\r\n通过继承 `Wechat` 类进行扩展，通过重写 `onSubscribe()` 等方法响应关注等请求：\r\n\r\n```php\r\nclass MyWechat extends Wechat {\r\n  protected function onSubscribe() {} // 用户关注\r\n  protected function onUnsubscribe() {} // 用户取消关注\r\n\r\n  protected function onText() {\r\n    // 收到文本消息时触发，此处为响应代码\r\n  }\r\n\r\n  protected function onImage() {} // 收到图片消息\r\n  protected function onLocation() {} // 收到地理位置消息\r\n  protected function onLink() {} // 收到链接消息\r\n  protected function onUnknown() {} // 收到未知类型消息\r\n}\r\n```\r\n-----\r\n\r\n使用 `getRequest()` 可以获取本次请求中的参数（不区分大小写）：\r\n\r\n```php\r\n$this-\u003egetRequest();\r\n// 无参数时，返回包含所有参数的数组\r\n\r\n$this-\u003egetRequest('msgtype');\r\n// 有参数且参数存在时，返回该参数的值\r\n\r\n$this-\u003egetRequest('ghost');\r\n// 有参数但参数不存在时，返回 NULL\r\n```\r\n\r\n所有请求均包含：\r\n\r\n```\r\nToUserName    接收方帐号（该公众号ID）\r\nFromUserName  发送方帐号（代表用户的唯一标识）\r\nCreateTime    消息创建时间（时间戳）\r\nMsgId         消息ID（64位整型）\r\n```\r\n\r\n文本消息请求：\r\n\r\n```\r\nMsgType  text\r\nContent  文本消息内容\r\n```\r\n\r\n图片消息请求：\r\n\r\n```\r\nMsgType  image\r\nPicUrl   图片链接\r\n```\r\n\r\n地理位置消息请求：\r\n\r\n```\r\nMsgType     location\r\nLocation_X  地理位置纬度\r\nLocation_Y  地理位置经度\r\nScale       地图缩放大小\r\nLabel       地理位置信息\r\n```\r\n\r\n链接消息请求：\r\n\r\n```\r\nMsgType      link\r\nTitle        消息标题\r\nDescription  消息描述\r\nUrl          消息链接\r\n```\r\n\r\n事件推送：\r\n\r\n```\r\nMsgType   event\r\nEvent     事件类型\r\nEventKey  事件 Key 值，与自定义菜单接口中 Key 值对应\r\n```\r\n\r\n其中，事件类型 `Event` 的值包括以下几种：\r\n\r\n```\r\nsubscribe    关注\r\nunsubscribe  取消关注\r\nCLICK        自定义菜单点击事件（未验证）\r\n```\r\n-----\r\n\r\n使用 `responseText()` 方法回复文本消息：\r\n\r\n```php\r\n$this-\u003eresponseText(\r\n  $content,  // 消息内容\r\n  $funcFlag  // 可选参数（默认为0），设为1时星标刚才收到的消息\r\n);\r\n```\r\n\r\n使用 `responseMusic()` 方法回复音乐消息：\r\n\r\n```php\r\n$this-\u003eresponseMusic(\r\n  $title,        // 音乐标题\r\n  $description,  // 音乐描述\r\n  $musicUrl,     // 音乐链接\r\n  $hqMusicUrl,   // 高质量音乐链接，Wi-Fi 环境下优先使用\r\n  $funcFlag      // 可选参数，默认为0，设为1时星标刚才收到的消息\r\n);\r\n```\r\n\r\n使用 `responseNews()` 方法回复图文消息：\r\n\r\n```php\r\n$this-\u003eresponseNews(\r\n  $items,    // 由单条图文消息类型 NewsResponseItem() 组成的数组\r\n  $funcFlag  // 可选参数，默认为0，设为1时星标刚才收到的消息\r\n)\r\n```\r\n\r\n其中单条图文消息类型 `NewsResponseItem()` 格式如下：\r\n\r\n```php\r\n$items[] = new NewsResponseItem(\r\n  $title,        // 图文消息标题\r\n  $description,  // 图文消息描述\r\n  $picUrl,       // 图片链接\r\n  $url           // 点击图文消息跳转链接\r\n);\r\n```\r\n-----\r\n\r\n最后，实例化 `MyWechat()` 并调用 `run()` 方法即可运行。\r\n\r\n```php\r\n$wechat = new MyWechat(\r\n  $token,  // 你在公众平台设置的 Token\r\n  $debug   // 调试模式，默认为 FALSE ，设为 TRUE 后可将错误通过文本消息回复显示\r\n);\r\n\r\n$wechat-\u003erun();\r\n```\r\n\r\nTODO\r\n-----\r\n1. 完善文档和注释；\r\n2. 完善异常处理；\r\n3. 提供 Composer 方式安装。\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonlan%2Fomnilab-wechat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhonlan%2Fomnilab-wechat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhonlan%2Fomnilab-wechat/lists"}