{"id":13861374,"url":"https://github.com/sbzhu/weworkapi_php","last_synced_at":"2025-07-14T09:31:34.261Z","repository":{"id":41557061,"uuid":"115499363","full_name":"sbzhu/weworkapi_php","owner":"sbzhu","description":"official lib of wework api","archived":false,"fork":false,"pushed_at":"2023-03-07T07:25:15.000Z","size":144,"stargazers_count":352,"open_issues_count":11,"forks_count":285,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-08-05T06:02:50.554Z","etag":null,"topics":["api","lib","php","tencent","wework"],"latest_commit_sha":null,"homepage":"https://work.weixin.qq.com/api/doc","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbzhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-27T08:28:17.000Z","updated_at":"2024-08-05T06:03:22.083Z","dependencies_parsed_at":"2024-08-05T06:13:24.807Z","dependency_job_id":null,"html_url":"https://github.com/sbzhu/weworkapi_php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbzhu%2Fweworkapi_php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbzhu%2Fweworkapi_php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbzhu%2Fweworkapi_php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbzhu%2Fweworkapi_php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbzhu","download_url":"https://codeload.github.com/sbzhu/weworkapi_php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225968812,"owners_count":17553142,"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":["api","lib","php","tencent","wework"],"created_at":"2024-08-05T06:01:19.964Z","updated_at":"2024-11-22T21:30:32.268Z","avatar_url":"https://github.com/sbzhu.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# About\nweworkapi_php 是为了简化开发者对企业微信API接口的使用而设计的，API调用库系列之php版本    \n包括企业API接口、消息回调处理方法、第三方开放接口等    \n本库仅做示范用，并不保证完全无bug；  \n另外，作者会不定期更新本库，但不保证与官方API接口文档同步，因此一切以[官方文档](https://work.weixin.qq.com/api/doc)为准。\n\n更多来自个人开发者的其它语言的库推荐：   \npython : https://github.com/sbzhu/weworkapi_python  abelzhu@tencent.com(企业微信团队)  \nruby ： https://github.com/mycolorway/wework  MyColorway(个人开发者)  \nphp : https://github.com/sbzhu/weworkapi_php  abelzhu@tencent.com(企业微信团队)  \ngolang : https://github.com/sbzhu/weworkapi_golang  ryanjelin@tencent.com(企业微信团队)  \ngolang : https://github.com/doubliekill/EnterpriseWechatSDK  1006401052yh@gmail.com(个人开发者)  \n\n# Requirement\n经测试，PHP 5.3.3 ~ 7.2.0 版本均可使用\n\n# Director \n\n├── api // API 接口  \n│   ├── datastructure // API接口需要使用到的一些数据结构  \n│   ├── examples // API接口的测试用例  \n│   ├── README.md  \n│   └── src // API接口的关键逻辑  \n├── callback // 消息回调的一些方法  \n├── config.php   \n├── README.md  \n└── utils // 一些基础方法  \n\n# Usage\n将本项目下载到你的目录，既可直接引用相关文件  \n```\ninclude_once(\"api/src/CorpAPI.class.php\");\n\n// 实例化 API 类\n$api = new CorpAPI($corpId='ww55ca070cb9b7eb22', $secret='ktmzrVIlUH0UW63zi7-JyzsgTL9NfwUhHde6or6zwQY');\n\ntry { \n    // 创建 User\n    $user = new User();\n    {\n        $user-\u003euserid = \"userid\";\n        $user-\u003ename = \"name\";\n        $user-\u003emobile = \"131488888888\";\n        $user-\u003eemail = \"sbzhu@ipp.cas.cn\";\n        $user-\u003edepartment = array(1); \n    } \n    $api-\u003eUserCreate($user);\n\n    // 获取User\n    $user = $api-\u003eUserGet(\"userid\");\n\n    // 删除User\n    $api-\u003eUserDelete(\"userid\"); \n} catch {\n    echo $e-\u003egetMessage() . \"\\n\";\n    $api-\u003eUserDelete(\"userid\");\n}\n```\n详细使用方法参考每个模块下的测试用例\n\n# 关于token的缓存\ntoken是需要缓存的，不能每次调用都去获取token，[否则会中频率限制](https://work.weixin.qq.com/api/doc#10013/%E7%AC%AC%E5%9B%9B%E6%AD%A5%EF%BC%9A%E7%BC%93%E5%AD%98%E5%92%8C%E5%88%B7%E6%96%B0access_token)  \n在本库的设计里，token是以类里的一个变量缓存的  \n比如api/src/CorpAPI.class.php 里的$accessToken变量  \n在类的生命周期里，这个accessToken都是存在的， 当且仅当发现token过期，CorpAPI类会自动刷新token   \n刷新机制在 api/src/API.class.php  \n所以，使用时，只需要全局实例化一个CorpAPI类，不要析构它，就可一直用它调函数，不用关心 token  \n```\n$api = new CorpAPI(corpid, corpsecret);\n$api-\u003edosomething()\n$api-\u003edosomething()\n$api-\u003edosomething()\n....\n```\n当然，如果要更严格的做的话，建议自行修改，```全局缓存token，比如存redis、存文件等```，失效周期设置为2小时。\n\n# Contact us\nabelzhu@tencent.com  \nxiqunpan@tencent.com  \n\n# \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbzhu%2Fweworkapi_php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbzhu%2Fweworkapi_php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbzhu%2Fweworkapi_php/lists"}