├── .gitignore ├── LICENSE ├── README.md ├── demo └── index.php └── src └── TimeCheer └── Weixin ├── API ├── Base.php ├── BizWIFI │ ├── Bar.php │ ├── Base.php │ ├── ConnectUrl.php │ ├── Device.php │ ├── Homepage.php │ ├── OpenPlugin.php │ ├── Qrcode.php │ ├── Shop.php │ └── Statistics.php ├── MP │ ├── AccessToken.php │ ├── AutoReply.php │ ├── Base.php │ ├── Component.php │ ├── Kefu.php │ ├── Mass.php │ ├── Material.php │ ├── Menu.php │ ├── Message.php │ ├── Poi.php │ ├── TemplateMessage.php │ ├── Ticket.php │ ├── User.php │ ├── UserGroup.php │ └── Wifi.php └── SNS │ └── OAuth2.php ├── Autoloader.php ├── Base.php ├── Open ├── Base.php └── OAuth2.php ├── QY └── OAuth2.php ├── QYAPI ├── AccessToken.php ├── Agent.php ├── Base.php ├── Batch.php ├── Crypt │ ├── ErrorCode.php │ ├── PKCS7Encoder.php │ ├── Prpcrypt.php │ ├── SHA1.php │ ├── WXBizMsgCrypt.php │ └── XMLParse.php ├── Department.php ├── Material.php ├── Media.php ├── Menu.php ├── Message.php ├── Service.php ├── Tag.php └── User.php └── Util └── HTTPClient.php /.gitignore: -------------------------------------------------------------------------------- 1 | nbproject/private/ 2 | build/ 3 | nbbuild/ 4 | dist/ 5 | nbdist/ 6 | nbactions.xml 7 | nb-configuration.xml 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "{}" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright 2015 Jimmy Chaw 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | 193 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeixinSDK4PHP 2 | 微信公众号SDK封装、PHP版本、目前主要从企业号开始 3 | -------------------------------------------------------------------------------- /demo/index.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_SET, array('shop_id' => (int) $shopId, 'bar_type' => (int) $barType), array(), true); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Base.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_GET, array(), array(), true); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Device.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_ADD, array('shop_id' => (int) $shopId, 'ssid' => $ssid, 'password' => $password), array(), true); 26 | } 27 | 28 | /** 29 | * 查询多个门店或指定门店的设备信息 30 | * @param int $pageIndex 分页下标,默认从1开始 31 | * @param int $pageSize 每页的个数,默认10个,最大20个 32 | * @param int $shopId 门店id 33 | * @return array{ 34 | * "errcode": 0, 35 | * "data": { 36 | * "totalcount": 2, 37 | * "pageindex": 1, 38 | * "pagecount": 1, 39 | * "records": [ 40 | * { 41 | * "shop_id": 429620, 42 | * "ssid": "WX123", 43 | * "bssid": "00:1f:7a:ad:5b:a9", 44 | * "protocol_type":4 45 | * }, 46 | * { 47 | * "shop_id": 429620, 48 | * "ssid": "WX123", 49 | * "bssid": "00:1f:7a:ad:5c:a8", 50 | * "protocol_type":4 51 | * } 52 | * ] 53 | * } 54 | * } 55 | */ 56 | public function query($pageIndex = 1, $pageSize = 10, $shopId) { 57 | $data = array('pageindex' => (int) $pageIndex, 'pagesize' => (int) $pageSize); 58 | if (!empty($shopId)) { 59 | $data['shop_id'] = (int) $shopId; 60 | } 61 | return $this->doPost(self::API_LIST, $data, array(), true); 62 | } 63 | 64 | /** 65 | * 删除设备 66 | * @param string $bssid 需要删除的无线网络设备无线mac地址,格式冒号分隔,字符长度17个,并且字母小写,例如:00:1f:7a:ad:5c:a8 67 | * @return string $errcode = 0 68 | */ 69 | public function delete($bssid) { 70 | return $this->doPost(self::API_DELETE, array('bssid' => $bssid), array(), true); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Homepage.php: -------------------------------------------------------------------------------- 1 | (int) $shopId, 'template_id' => (int) $templateId); 23 | if ($templateId == 1 && !empty($url)) { 24 | $data['struct']['url'] = $url; 25 | } 26 | return $this->doPost(self::API_SET, $data, array(), true); 27 | } 28 | 29 | /** 30 | * 查询商家主页 31 | * @param int $shopId 查询的门店的id (必填) 32 | * @return array { 33 | * "errcode": 0, 34 | * "data": { 35 | * "shop_id": 429620, 36 | * "template_id": 1, 37 | * "url": " http://wifi.weixin.qq.com/" 38 | * } 39 | * } 40 | */ 41 | public function get($shopId) { 42 | return $this->doPost(self::API_GET, array('shop_id' => (int) $shopId), array(), true); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/OpenPlugin.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_OPEN, array('callback_url' => $callbackUrl), array(), true); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Qrcode.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_GET, array('shop_id' => (int) $shopId, 'img_id' => (int) $imgId), array(), true); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Shop.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_LIST, array('pageindex' => (int) $pageIndex, 'pagesize' => (int) $pageSize), array(), true); 47 | } 48 | 49 | /** 50 | * 查询某门店的WiFi信息 51 | * @param int $shopId 门店id 52 | * @return array { 53 | * "errcode": 0, 54 | * "data": { 55 | * "shop_name": "南山店", 56 | * "ssid": "WX4123", 57 | * "password": "123456789", 58 | * "protocol_type": 4, 59 | * "ap_count": 2, 60 | * "template_id": 1, 61 | * "homepage_url": "http://www.weixin.qq.com/", 62 | * "bar_type": 1 63 | * } 64 | * } 65 | */ 66 | public function get($shopId) { 67 | return $this->doPost(self::API_GET, array('shop_id' => (int) $shopId), array(), true); 68 | } 69 | 70 | /** 71 | * 清空门店网络及设备 72 | * @param int $shopId 73 | * @return array{ "errcode": 0} 74 | */ 75 | public function clean($shopId) { 76 | return $this->doPost(self::API_CLEAN, array('shop_id' => (int) $shopId),array(), true); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/BizWIFI/Statistics.php: -------------------------------------------------------------------------------- 1 | $beginDate, 'end_date' => $endDate, 'shop_id' => $shopId); 47 | return $this->doPost(self::API_LIST, $data, array(), true); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/AccessToken.php: -------------------------------------------------------------------------------- 1 | '成功', //(no error) 19 | '61451' => '参数错误', //(invalid parameter) 20 | '61452' => '无效客服账号', //(invalid kf_account) 21 | '61453' => '账号已存在', //(kf_account exsited) 22 | '61454' => '账号名长度超过限制(前缀10个英文字符)', //(invalid kf_acount length) 23 | '61455' => '账号名包含非法字符(英文+数字)', //(illegal character in kf_account) 24 | '61456' => '账号个数超过限制(100个客服账号)', //(kf_account count exceeded) 25 | '61457' => '无效头像文件类型', //(invalid file type) 26 | ); 27 | 28 | /** 29 | * 添加客户帐号 30 | * 31 | * @param string $kf_acount 完整客服账号,格式为:账号前缀@公众号微信号 32 | * @param string $nickname 客服昵称,最长6个汉字或12个英文字符 33 | * @param string $password 客服账号登录密码,格式为密码明文的32位加密MD5值 34 | * @return boolean 35 | */ 36 | public function add($kf_acount, $nickname, $password) { 37 | $params = array( 38 | 'kf_account' => $kf_acount, 39 | 'nickname' => $nickname, 40 | 'password' => $password, 41 | ); 42 | $res = $this->doPost(self::API_ADD, $params); 43 | 44 | if (isset($res['errcode']) && $res['errcode'] === 0) { 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | 51 | /** 52 | * 设置客户信息 53 | * 54 | * @param string $kf_acount 完整客服账号,格式为:账号前缀@公众号微信号 55 | * @param string $nickname 客服昵称,最长6个汉字或12个英文字符 56 | * @param string $password 客服账号登录密码,格式为密码明文的32位加密MD5值 57 | * @return boolean 58 | */ 59 | public function update($kf_acount, $nickname, $password) { 60 | $params = array( 61 | 'kf_account' => $kf_acount, 62 | 'nickname' => $nickname, 63 | 'password' => $password, 64 | ); 65 | $res = $this->doPost(self::API_UPDATE, $params); 66 | 67 | if (isset($res['errcode']) && $res['errcode'] === 0) { 68 | return true; 69 | } 70 | 71 | return false; 72 | } 73 | 74 | /** 75 | * 给客服帐号上传头像 76 | * 77 | * @param string $media 头像图片 78 | * @param string $kf_account 完整客服账号,格式为:账号前缀@公众号微信号 79 | * @return boolean 80 | */ 81 | public function uploadHeadImg($media, $kf_account) { 82 | $params = array( 83 | 'media' => '@' . $media, 84 | ); 85 | $res = $this->doPost(self::API_UPDATE, $params, array('kf_account' => $kf_account)); 86 | 87 | if (isset($res['errcode']) && $res['errcode'] === 0) { 88 | return true; 89 | } 90 | 91 | return false; 92 | } 93 | 94 | /** 95 | * 删除客户帐号 96 | */ 97 | public function delete($kf_account) { 98 | 99 | $res = $this->doGet(self::API_DELETE, array('kf_account' => $kf_account)); 100 | 101 | if (isset($res['errcode']) && $res['errcode'] === 0) { 102 | return true; 103 | } 104 | 105 | return false; 106 | } 107 | 108 | /** 109 | * 获取客服基本信息 110 | * 111 | * @return boolean|array array(array('kf_account'=>'***', 'kf_headimgurl'=>'***', 'kf_id'=>'1001', 'kf_nick'=>'***'),...) 112 | */ 113 | public function getKFList() { 114 | 115 | $res = $this->doGet(self::API_LIST); 116 | 117 | if (!isset($res['kf_list'])) { 118 | return false; 119 | } 120 | 121 | return $res['kf_list']; 122 | } 123 | 124 | /** 125 | * 获取在线客户接待状态 126 | * 127 | * @return boolean|array array(array('kf_account'=>'***', 'status'=>1, 'kf_id'=>'1001', 'auto_accept'=>0, 'accepted_case'=>1),...) 128 | */ 129 | public function getOnlineKFList() { 130 | 131 | $res = $this->doGet(self::API_LIST_ONLINE); 132 | 133 | if (!isset($res['kf_online_list'])) { 134 | return false; 135 | } 136 | 137 | return $res['kf_online_list']; 138 | } 139 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Mass.php: -------------------------------------------------------------------------------- 1 | $msg_id, 25 | ); 26 | $res = $this->doPost(self::API_GET, $params); 27 | 28 | return !empty($res['msg_status']) ? $res['msg_status'] : false; 29 | } 30 | 31 | /** 32 | * 发送消息 33 | * 34 | * @param string|array $data 35 | * @param boolean $is_all send/sendall 36 | * @return boolean 37 | */ 38 | public function send($data, $is_all = false) { 39 | if (is_array($data)) { 40 | $data = json_encode($data); 41 | } else if (!json_decode($data)) { 42 | return false; 43 | } 44 | $res = $this->httpRequest($is_all ? self::API_SEND_ALL : self::API_SEND, $data); 45 | 46 | if (isset($res['errcode']) && $res['errcode'] == 0) { 47 | return $res; 48 | } 49 | 50 | return false; 51 | } 52 | 53 | /** 54 | * 删除群发 55 | *
56 | * 1、只有已经发送成功的消息才能删除 57 | * 2、删除消息是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片。 58 | * 3、删除群发消息只能删除图文消息和视频消息,其他类型的消息一经发送,无法删除。 59 | * 4、如果多次群发发送的是一个图文消息,那么删除其中一次群发,就会删除掉这个图文消息也,导致所有群发都失效 60 | *61 | * @param int $msg_id 发送出去的消息ID 62 | * @return boolean 63 | */ 64 | public function delete($msg_id) { 65 | $params = array( 66 | 'msg_id' => $msg_id, 67 | ); 68 | $res = $this->httpRequest($this->url . 'mass/delete?' . http_build_query($this->getParams()), $params, 'post'); 69 | 70 | if (isset($res['errcode']) && $res['errcode'] == 0) { 71 | return true; 72 | } 73 | 74 | return false; 75 | } 76 | 77 | /** 78 | * 根据分组进行群发【订阅号与服务号认证后均可用】 79 | * 80 | * @param string $media_id 81 | * @param string $msgtype 'mpnews', 'text', 'image', 'voice', 'mpvideo','wxcard' 82 | * @param boolean $is_to_all 83 | * @param int $group_id 84 | * @return false|array 85 | */ 86 | public function sendByGroup($media_id, $msgtype = 'mpnews', $is_to_all = TRUE, $group_id = 0) { 87 | $params = array( 88 | 'filter' => array('is_to_all' => ($is_to_all ? true : false)), 89 | $msgtype => array('media_id' => $media_id), 90 | 'msgtype' => $msgtype 91 | ); 92 | if (!$is_to_all) { 93 | if (!is_numeric($group_id) || $group_id < 0) { 94 | return false; 95 | } 96 | $params['filter']['group_id'] = $group_id; 97 | } 98 | 99 | $res = $this->httpRequest($this->url . 'mass/sendall?' . http_build_query($this->getParams()), $params, 'post'); 100 | 101 | if (isset($res['errcode']) && $res['errcode'] == 0) { 102 | return $res; 103 | } 104 | 105 | return false; 106 | } 107 | 108 | /** 109 | * 根据OpenID列表群发【订阅号不可用,服务号认证后可用】 110 | * 111 | * @param string|array $media 112 | * @param string $msgtype 'news', 'mpnews', 'text', 'image', 'voice', 'video','wxcard' 113 | * @param array|string $openids 114 | * @return false|array 115 | */ 116 | public function sendByOpenid($media, $msgtype = 'mpnews', $openids = null) { 117 | if (empty($openids)) { 118 | return false; 119 | } 120 | if (!is_array($openids)) { 121 | $openids = explode(',', $openids); 122 | } else { 123 | $openids = array_values($openids); 124 | } 125 | 126 | $params = array( 127 | 'touser' => $openids, 128 | 'msgtype' => $msgtype, 129 | $msgtype => array('media_id' => $media) 130 | ); 131 | switch ($msgtype) { 132 | case 'wxcard': 133 | $params[$msgtype] = array('card_id' => $media); 134 | break; 135 | case 'text': 136 | $params[$msgtype] = array('content' => $media); 137 | break; 138 | case 'video': 139 | $params[$msgtype]['title'] = $media['title']; 140 | $params[$msgtype]['description'] = $media['description']; 141 | break; 142 | default: 143 | break; 144 | } 145 | 146 | $res = $this->httpRequest($this->url . 'mass/send?' . http_build_query($this->getParams()), $params, 'post'); 147 | 148 | if (isset($res['errcode']) && $res['errcode'] == 0) { 149 | return $res; 150 | } 151 | 152 | return false; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Material.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_GET, array('media_id' => $mediaId), array(), true); 38 | } 39 | 40 | /** 41 | * 新增除图文素材外的其他类型永久素材 42 | * @param array $media 43 | * @param string $type 44 | * @param array $videoDescription 视频素材需要POST另一个表单 45 | * @return array array('media_id' => '', 'url' => '视频素材返回url') 46 | */ 47 | public function add($media, $type = self::TYPE_IMAGE, $videoDescription = array()) { 48 | if (!file_exists($media)) { 49 | $this->setError('文件路径不正确'); 50 | 51 | return false; 52 | } 53 | 54 | // 兼容php5.3-5.6 curl模块的上传操作 55 | if (version_compare(PHP_VERSION, '5.3.0') >= 0 && class_exists('CURLFile')) { 56 | $data = array('media' => new \CURLFile(realpath($media))); 57 | } else { 58 | $data = array('media' => '@' . realpath($media)); 59 | } 60 | $data['type'] = $type; 61 | if ($type == self::TYPE_VEDIO) { 62 | $data['description'] = json_encode($videoDescription); 63 | } 64 | 65 | return $this->doPost(self::API_ADD, $data); 66 | } 67 | 68 | /** 69 | * 添加图文素材 70 | * 永久素材的数量是有上限的,请谨慎新增。图文消息素材和图片素材的上限为5000,其他类型为1000 71 | * 素材的格式大小等要求与公众平台官网一致。 72 | * 具体是,图片大小不超过2M,支持bmp/png/jpeg/jpg/gif格式, 73 | * 语音大小不超过5M,长度不超过60秒,支持mp3/wma/wav/amr格式 74 | * 75 | * 在图文消息的具体内容中,将过滤外部的图片链接, 76 | * 开发者可以通过$this->uploadNewsImage接口上传图片得到URL,放到图文内容中使用 77 | * @param array $articles 多图文列表 78 | * @return string media_id 79 | */ 80 | public function addNews($articles) { 81 | return $this->doPost(self::API_ADD_NEWS, array('articles' => $articles)); 82 | } 83 | 84 | /** 85 | * 上传图文消息内的图片 86 | * 订阅号与服务号认证后均可用 87 | * @param array $media 88 | * @return string 返回图片在微信服务器的url 89 | */ 90 | public function uploadNewsImage($media) { 91 | if (!file_exists($media)) { 92 | $this->setError('文件路径不正确'); 93 | 94 | return false; 95 | } 96 | 97 | // 兼容php5.3-5.6 curl模块的上传操作 98 | if (version_compare(PHP_VERSION, '5.5.0') >= 0 && class_exists('CURLFile')) { 99 | $data = array('media' => new \CURLFile(realpath($media))); 100 | } else { 101 | $data = array('media' => '@' . realpath($media)); 102 | } 103 | 104 | return $this->doPost(self::API_UPLOAD_NEWS_IMG, $data); 105 | } 106 | 107 | /** 108 | * 删除不再需要的永久素材 109 | * @param string $mediaId 110 | * @return bool 111 | */ 112 | public function del($mediaId) { 113 | return $this->doPost(self::API_DELETE, array('media_id' => $mediaId)); 114 | } 115 | 116 | /** 117 | * 对永久图文素材进行修改 一次修改多图文中的一篇 118 | * @param string $mediaId 119 | * @param array $article 120 | * @param int $index 要更新的文章在图文消息中的位置 多图文消息时,此字段才有意义)第一篇为0 121 | * @return bool 122 | */ 123 | public function updateNews($mediaId, $article, $index = 0) { 124 | return $this->doPost(self::API_UPDATE_NEWS, array('media_id' => $mediaId, 'index' => $index, 'articles' => $article)); 125 | } 126 | 127 | /** 128 | * 获取素材总数 129 | * @return array { 130 | * "voice_count":COUNT, 131 | * "video_count":COUNT, 132 | * "image_count":COUNT, 133 | * "news_count":COUNT 134 | * } 135 | */ 136 | public function getCount() { 137 | return $this->doGet(self::API_COUNT); 138 | } 139 | 140 | /** 141 | * 分类型获取永久素材的列表 142 | * @param string $type 图片(image)、视频(video)、语音 (voice)、图文(news) 143 | * @param int $offset 0表示从第一个素材 返回 144 | * @param int $count 返回素材的数量,取值在1到20之间 145 | * @return array 146 | */ 147 | public function getAll($type = self::TYPE_IMAGE, $offset = 0, $count = 20) { 148 | return $this->doPost(self::API_LIST, array('type' => $type, 'offset' => $offset, 'count' => $count)); 149 | } 150 | 151 | /** 152 | * 上传临时素材 153 | * @param array $media 154 | * @param string $type 图片(image)、语音(voice)、视频(video)和缩略图(thumb) 155 | */ 156 | public function uploadTmp($media, $type = self::TYPE_IMAGE) { 157 | if (!file_exists($media)) { 158 | $this->setError('文件路径不正确'); 159 | 160 | return false; 161 | } 162 | 163 | // 兼容php5.5以上 curl模块的上传操作 164 | if (version_compare(PHP_VERSION, '5.3.0') >= 0 && class_exists('CURLFile')) { 165 | $data = array('media' => new \CURLFile(realpath($media))); 166 | } else { 167 | $data = array('media' => '@' . realpath($media)); 168 | } 169 | $data['type'] = $type; 170 | 171 | return $this->doPost(self::API_UPLOAD_TMP, $data); 172 | } 173 | 174 | /** 175 | * 临时素材下载。请注意,由于视频文件不支持https下载,该方法暂不能下载视频 176 | * @param string $mediaId 177 | * @return mixed 178 | */ 179 | public function downloadTmp($mediaId) { 180 | return $this->doGet(self::API_DOWNLOAD_TMP, array('media_id' => $mediaId)); 181 | } 182 | 183 | /** 184 | * 用于群发 上传图文消息素材【订阅号与服务号认证后均可用】 185 | * @link http://mp.weixin.qq.com/wiki/14/0c53fac3bdec3906aaa36987b91d64ea.html#.E4.B8.8A.E4.BC.A0.E5.9B.BE.E6.96.87.E6.B6.88.E6.81.AF.E7.B4.A0.E6.9D.90.E3.80.90.E8.AE.A2.E9.98.85.E5.8F.B7.E4.B8.8E.E6.9C.8D.E5.8A.A1.E5.8F.B7.E8.AE.A4.E8.AF.81.E5.90.8E.E5.9D.87.E5.8F.AF.E7.94.A8.E3.80.91 186 | * @param array $articles 187 | */ 188 | public function uploadNews($articles) { 189 | return $this->doPost(self::API_UPLOAD_NEWS, array('articles' => $articles)); 190 | } 191 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Menu.php: -------------------------------------------------------------------------------- 1 | 19 | 按钮结构: 20 | {"type":"***","name":"***","key":"***"} 21 | {"type":"view","name":"***","url":"***"} 22 | {"type":"media_id/view_limited","name":"***","media_id":"***"} 23 | {"name":"***","sub_button":[{},{},...]} 24 | 25 | * @param array $data 26 | * @return boolean 27 | */ 28 | public function create($data) { 29 | $params = array( 30 | 'button' => $data, 31 | ); 32 | $res = $this->doPost(self::API_CREATE, $params); 33 | 34 | if (isset($res['errcode']) && $res['errcode'] === 0) { 35 | return true; 36 | } 37 | 38 | return false; 39 | } 40 | 41 | /** 42 | * 删除当前使用的自定义菜单 43 | * 44 | * @return boolean 45 | */ 46 | public function delete() { 47 | 48 | return $this->doGet(self::API_DELETE); 49 | } 50 | 51 | /** 52 | * 获取(API调用设置的)自定义菜单结构 53 | * 54 | * @return boolean|array 55 | */ 56 | public function getList() { 57 | 58 | $res = $this->doGet(self::API_GET); 59 | 60 | if (!isset($res['menu']['button'])) { 61 | return false; 62 | } 63 | 64 | return $res['menu']['button']; 65 | } 66 | 67 | /** 68 | * 公众号当前使用的自定义菜单的配置 69 | * 70 | * @return boolean|array 71 | */ 72 | public function getCurrentList() { 73 | $res = $this->doGet(self::API_GET_CURRENT); 74 | 75 | if (!isset($res['selfmenu_info']['button'])) { 76 | return false; 77 | } 78 | 79 | return $res['selfmenu_info']['button']; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Message.php: -------------------------------------------------------------------------------- 1 | $openids, 54 | 'msgtype' => $msgtype 55 | ); 56 | switch ($msgtype) { 57 | case 'wxcard': 58 | $params[$msgtype] = array('card_id' => $media); 59 | break; 60 | case 'text': 61 | $params[$msgtype] = array('content' => $media); 62 | break; 63 | case 'video': 64 | $params[$msgtype]['title'] = $media['title']; 65 | $params[$msgtype]['description'] = $media['description']; 66 | break; 67 | case 'news': 68 | $params[$msgtype]['articles'] = $media; 69 | break; 70 | default: 71 | break; 72 | } 73 | 74 | $res = $this->httpRequest($this->url . 'custom/send?' . http_build_query($this->getParams()), $params, 'post'); 75 | //\Think\Log::write($res, \Think\Log::DEBUG, null); 76 | 77 | if (isset($res['errcode']) && $res['errcode'] == 0) { 78 | return $res; 79 | } 80 | 81 | return false; 82 | } 83 | 84 | /** 85 | * 发送消息给指定用户,在手机端预览消息的样式和排版 86 | * 87 | * @param string|array $media 88 | * @param string $msgtype 'mpnews', 'text', 'image', 'voice', 'mpvideo','wxcard' 89 | * @param string $openid 90 | * @param string $send_type openid/wechatname 91 | * @return boolean|array 92 | */ 93 | public function preview($media, $msgtype, $openid, $send_type = 'openid') { 94 | $params = array( 95 | ($send_type == 'openid' ? 'touser' : 'towxname') => $openid, 96 | 'msgtype' => $msgtype, 97 | $msgtype => array('media_id' => $media) 98 | ); 99 | switch ($msgtype) { 100 | case 'wxcard': 101 | $params[$msgtype] = array('card_id' => $media['card_id'], 'card_ext' => $media['card_ext']); 102 | break; 103 | case 'text': 104 | $params[$msgtype] = array('content' => $media); 105 | break; 106 | default: 107 | break; 108 | } 109 | $res = $this->httpRequest($this->url . 'mass/delete?' . http_build_query($this->getParams()), $params, 'post'); 110 | 111 | if (isset($res['errcode']) && $res['errcode'] == 0) { 112 | return $res; 113 | } 114 | 115 | return false; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Poi.php: -------------------------------------------------------------------------------- 1 | doPost(self::API_UPLOAD_IMAGE); 26 | } 27 | 28 | /** 29 | * 创建门店 30 | * @param array $information 门店的信息 31 | * @return array { 32 | * "errcode":0, 33 | * "errmsg":"ok" 34 | * } 35 | */ 36 | public function add($information) { 37 | return $this->doPost(self::API_ADD, $information, array(), true); 38 | } 39 | 40 | /** 41 | * 查询门店详细信息 42 | * @param int $poiId 门店id 43 | * @return araay { 44 | * "errcode":0, 45 | * "errmsg":"ok", 46 | * "business ":{ 47 | * "base_info":{ 48 | * "sid":"001", 49 | * "business_name":"麦当劳", 50 | * "branch_name":"艺苑路店", 51 | * "province":"广东省", 52 | * "city":"广州市", 53 | * "address":"海珠区艺苑路11 号", 54 | * "telephone":"020-12345678", 55 | * "categories":["美食,小吃快餐"], 56 | * "offset_type":1, 57 | * "longitude":115.32375, 58 | * "latitude":25.097486, 59 | * "photo_list":[{"photo_url":"https:// XXX.com"} , {"photo_url":"https://XXX.com"}], 60 | * "recommend":"麦辣鸡腿堡套餐,麦乐鸡,全家桶", 61 | * "special":"免费wifi,外卖服务", 62 | * "introduction":"麦当劳是全球大型跨国连锁餐厅,1940 年创立于美国,在世界上大", 63 | * "open_time":"8:00-20:00", 64 | * "avg_price":35 65 | * "available_state":3 66 | * "update_status":0 67 | * } 68 | * } 69 | * } 70 | */ 71 | public function get($poiId) { 72 | return $this->doPost(self::API_GET, array('poi_id' => $poiId), array(), true); 73 | } 74 | 75 | /** 76 | * 查询门店列表 77 | * $param int $begin 开始位置,0 即为从第一条开始查询 (必填) 78 | * @param int $limit 返回数据条数,最大允许50,默认为20 (必填) 79 | * @return array{ 80 | * "errcode": 81 | * "errmsg": 82 | * "business_list":[ 83 | * {"base_info":{ 84 | * "sid":"101", 85 | * "business_name":"麦当劳", 86 | * "branch_name":"艺苑路店", 87 | * "address":"艺苑路11号", 88 | * "telephone":"020-12345678", 89 | * "categories":["美食,快餐小吃"], 90 | * "city":"广州市", 91 | * "province":"广东省", 92 | * "offset_type":1, 93 | * "longitude":115.32375, 94 | * "latitude":25.097486, 95 | * "photo_list":[{"photo_url":"http: ...."}], 96 | * "introduction":"麦当劳是全球大型跨国连锁餐厅,1940 年创立于美国", 97 | * "recommend":"麦辣鸡腿堡套餐,麦乐鸡,全家桶", 98 | * "special":"免费wifi,外卖服务", 99 | * "open_time":"8:00-20:00", 100 | * "avg_price":35, 101 | * "poi_id":"285633617", 102 | * "available_state":3, 103 | * "district":"海珠区", 104 | * "update_status":0 105 | * }},...... 106 | * ] 107 | * "total_count":"3", 108 | * } 109 | */ 110 | public function query($begin, $limit = 20) { 111 | return $this->doPost(self::API_LIST, array('begin' => $begin, 'limit' => $limit), array(), true); 112 | } 113 | 114 | /** 115 | * 修改门店服务信息 116 | * @param int $poiId 门店id 117 | * @param array $details 门店修改信息 118 | * @return array{ 119 | * "errcode":0, 120 | * "errmsg":"ok" 121 | * } 122 | */ 123 | public function update($poiId, $details) { 124 | return $this->doPost(self::API_UPDATE, array('poi_id' => $poiId, 'details' => $details)); 125 | } 126 | 127 | /** 128 | * 删除门店 129 | * @param int $poiId 门店id 130 | * @return array{ 131 | * "errcode":0, 132 | * "errmsg":"ok" 133 | * } 134 | */ 135 | public function delete($poiId) { 136 | return $this->doPost(self::API_DELETE, array('poi_id' => $poiId)); 137 | } 138 | 139 | /** 140 | * 门店类目标 141 | * @return string $categofy_list 142 | */ 143 | public function category() { 144 | return $this->doGet(self::API_CATEGORY); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/TemplateMessage.php: -------------------------------------------------------------------------------- 1 | doGet(self::API_LIST, $data); 32 | } 33 | 34 | /** 35 | * 通过OpenID来获取用户基本信息 36 | * @link http://mp.weixin.qq.com/wiki/17/c807ee0f10ce36226637cebf428a0f6d.html 37 | * @param string $openId 38 | * @return array 39 | */ 40 | public function getInfo($openId) { 41 | return $this->doGet(self::API_INFO, array('openid' => $openId)); 42 | } 43 | 44 | /** 45 | * 通过多个OpenID批量获取用户基本信息 46 | * @link http://mp.weixin.qq.com/wiki/17/c807ee0f10ce36226637cebf428a0f6d.html 47 | * @param array $openIds 48 | */ 49 | public function getAllInfo($openIds) { 50 | $data = array(); 51 | foreach ($openIds as $openid) { 52 | $data[] = array('openid' => $openid, 'lang' => 'zh-CN'); 53 | } 54 | 55 | return $this->doPost(self::API_INFOS, array('user_list' => $data)); 56 | } 57 | 58 | /** 59 | * 设置备注名 该接口暂时开放给微信认证的服务号 60 | * @param string $openId 61 | * @param string $remark 62 | * @return bool 63 | */ 64 | public function updateRemark($openId, $remark) { 65 | return $this->doPost(self::API_UPDATE_REMARK, array( 66 | 'openid' => $openId, 67 | 'remark' => $remark 68 | )); 69 | } 70 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/UserGroup.php: -------------------------------------------------------------------------------- 1 | array( 29 | 'name' => $name, 30 | ), 31 | ); 32 | 33 | return $this->doPost(self::API_CREATE, $data); 34 | } 35 | 36 | /** 37 | * 查询所有分组 38 | * @return array 39 | */ 40 | public function getAll() { 41 | return $this->doGet(self::API_LIST); 42 | } 43 | 44 | /** 45 | * 查询用户所在分组 46 | * @param string $openId 47 | * @return int group id 48 | */ 49 | public function getIdByOpenId($openId) { 50 | return $this->doPost(self::API_GETID, array('openid' => $openId)); 51 | } 52 | 53 | /** 54 | * 修改分组名 55 | * @param int $id 56 | * @param array $name 57 | * @return bool 58 | */ 59 | public function update($id, $name) { 60 | return $this->doPost(self::API_UPDATE, array( 61 | 'group' => array('id' => $id, 'name' => $name) 62 | )); 63 | } 64 | 65 | /** 66 | * 移动用户分组 67 | * @param int $toGroupId 分组id 68 | * @param string $openId 69 | * @return bool 70 | */ 71 | public function moveUser($toGroupId, $openId) { 72 | return $this->doPost(self::API_MOVE_USER, array( 73 | 'openid' => $openId, 74 | 'to_groupid' => $toGroupId 75 | )); 76 | } 77 | 78 | /** 79 | * 批量移动用户分组 80 | * @param int $toGroupId 81 | * @param array $openIds 82 | * @return bool 83 | */ 84 | public function moveUsers($toGroupId, $openIds) { 85 | return $this->doPost(self::API_MOVE_USERS, array( 86 | 'openid_list' => $openIds, 87 | 'to_groupid' => $toGroupId 88 | )); 89 | } 90 | 91 | /** 92 | * 删除分组 93 | * @param int $id 94 | * @return bool 95 | */ 96 | public function delete($id) { 97 | return $this->doPost(self::API_DELETE, array( 98 | 'group' => array('id' => $id) 99 | )); 100 | } 101 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/MP/Wifi.php: -------------------------------------------------------------------------------- 1 | doPost(self::WIFI_OPEN,array('callback_url'=>$callback_url),array(),true); 33 | } 34 | 35 | /** 36 | * 获取WiFi门店列表 37 | * 微信连WiFi下的所有接口中的shop_id,必需先通过此接口获取。 38 | * @param int $pageindex 分页下标,默认从1开始 39 | * @param int $pagesize 每页的个数,默认10个,最大20个 40 | */ 41 | public function shopList($pageindex,$pagesize){ 42 | return $this->doPost(self::WIFI_SHOP_LIST,array('pageindex'=>$pageindex,'pagesize'=>$pagesize),array(),true); 43 | } 44 | 45 | /** 46 | * 查询门店的WiFi信息 47 | * @param int $shop_id 门店id 48 | */ 49 | public function shopDetails($shop_id){ 50 | return $this->doPost(self::WIFI_SHOP_DETAILS,array('shop_id'=>$shop_id),array(),true); 51 | } 52 | 53 | /** 54 | * 添加密码型设备 55 | * 本接口只支持添加密码型设备。 56 | * 多台设备必须使用相同的 ssid 和 密码 57 | * @param int $shop_id 门店id (必填) 58 | * @param int $ssid 设备id (必填) 59 | * @param string $password 设备密码 (必填) 60 | */ 61 | public function deviceAdd($shop_id,$ssid,$password){ 62 | return $this->doPost(self::WIFI_DEVICE_ADD,array('shop_id'=>$shop_id,'ssid'=>$ssid,'password'=>$password),array(),true); 63 | } 64 | 65 | /** 66 | * 查询多个门店或指定门店的设备信息 67 | * @param int $pageindex 分页下标,默认从1开始 68 | * @param int $pagesize 每页的个数,默认10个,最大20个 69 | * @param int $shop_id 门店id 70 | */ 71 | public function deviceList($pageindex,$pagesize,$shop_id){ 72 | return $this->doPost(self::WIFI_DEVICE_LIST,array('pageindex'=>$pageindex,'pagesize'=>$pagesize,'shop_id'=>$shop_id),array(),true); 73 | } 74 | 75 | /** 76 | * 删除设备 77 | * @param string $bssid 需要删除的无线网络设备无线mac地址,格式冒号分隔,字符长度17个,并且字母小写,例如:00:1f:7a:ad:5c:a8 78 | * @return 79 | */ 80 | public function deviceDelete($bssid){ 81 | return $this->doPost(self::WIFI_DEVICE_DELETE,array('bssid'=>$bssid),array(),true); 82 | } 83 | /** 84 | * 获取物料二维码 85 | * @param int $shop_id 门店id (必填) 86 | * @param int 3img_id 二维码样式编号 0-纯二维码 1-二维码物料 (必填) 87 | * @return url 二维码图片url 88 | */ 89 | public function qrcodeGet($shop_id,$img_id){ 90 | return $this->doPost(self::WIFI_QRCODE_GET,array('shop_id'=>$shop_id,'img_id'=>$img_id),array(),true); 91 | } 92 | 93 | /** 94 | * 获取公众号连网URL 95 | * @return connect_url 96 | */ 97 | public function connectUrl(){ 98 | return $this->doPost(self::WIFI_CONNECTURL_GET,array(),array(),true); 99 | } 100 | 101 | /** 102 | * 设置商家主页 103 | * @param int $shop_id 门店id (必填) 104 | * @param int $template_id 模板id 0-默认模板 1-自定义url (必填) 105 | * @param $struct 模板结构,当template_id为0时可以不填 106 | * @param $url 自定义链接,当template_id为1时必填 107 | */ 108 | public function setHomepage($shop_id,$template_id=0,$struct,$url){ 109 | if($template_id ==1){ 110 | 111 | } 112 | return $this->doPost(self::WIFI_HOMEPAGE_SET,array('shop_id'=>$shop_id,'template_id'=>$template_id),array(),true); 113 | } 114 | 115 | /** 116 | * 查询商家主页 117 | * @param int $shop_id 查询的门店的id (必填) 118 | * @return shop_id template_id url 119 | */ 120 | public function getHomepage($shop_id){ 121 | return $this->doPost(self::WIFI_HOMEPAGE_GET,array('shop_id'=>$shop_id),array(),true); 122 | } 123 | 124 | /** 125 | * 设置顶部常驻入口文案 126 | * @param int $shop_id 门店id 127 | * @param int $bar_type 顶部常驻入口上显示的文本内容:0--欢迎光临+公众号名称;1--欢迎光临+门店名称;2--已连接+公众号名称+WiFi;3--已连接+门店名称+Wi-Fi 128 | */ 129 | public function setText($shop_id,$bar_type=0){ 130 | return $this->doPost(self::WIFI_BAR_SET,array($shop_id,$bar_type),array(),true); 131 | } 132 | 133 | /** 134 | * 数据统计 135 | * @param time $begin_date 起始日期时间,格式yyyy-mm-dd,最长时间跨度为30天 136 | * @param time $end_date 结束日期时间戳,格式yyyy-mm-dd,最长时间跨度为30天 137 | * @param int $shop_id 按门店ID搜索,-1为总统计 138 | */ 139 | public function statistics($begin_date,$end_date,$shop_id){ 140 | return $this->doPost(self::WIFI_STATISTICS,array('begin_date'=>$begin_date,'end_date'=>$end_date,'shop_id'=>$shop_id),array(),true); 141 | } 142 | 143 | /** 144 | * 145 | */ 146 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/API/SNS/OAuth2.php: -------------------------------------------------------------------------------- 1 | doGet(self::API_TOKEN, array( 26 | 'appid' => $appId, 27 | 'secret' => $appSecret, 28 | 'grant_type' => 'authorization_code', 29 | 'code' => $code 30 | )); 31 | } 32 | 33 | /** 34 | * 刷新access_token 35 | * @param string $appId 36 | * @param string $refreshToken 37 | * @return array 38 | */ 39 | public function refreshAccessToken($appId, $refreshToken) { 40 | return $this->doGet(self::API_REFRESH_TOKEN, array( 41 | 'appid' => $appId, 42 | 'grant_type' => 'refresh_token', 43 | 'refresh_token' => $refreshToken 44 | )); 45 | } 46 | 47 | /** 48 | * 拉取用户信息(需scope为 snsapi_userinfo) 49 | * @param string $accessToken 50 | * @param string $openId 51 | * @return array 52 | */ 53 | public function getUser($accessToken, $openId) { 54 | return $this->doGet(self::API_USER, array( 55 | 'access_token' => $accessToken, 56 | 'openid' => $openId, 57 | 'lang' => 'zh_CN' 58 | )); 59 | } 60 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/Autoloader.php: -------------------------------------------------------------------------------- 1 | _dir = $dir; 24 | } 25 | 26 | /** 27 | * 向PHP注册SPL autoloader 28 | * @param string $dir 指定加载目录 29 | * @return void 30 | */ 31 | public static function register($dir = null) { 32 | ini_set('unserialize_callback_func', 'spl_autoload_call'); 33 | 34 | spl_autoload_register(array(new self($dir), 'autoload'), FALSE, TRUE); 35 | } 36 | 37 | /** 38 | * 系统自动注册 39 | * 40 | * @param string $class 类名 41 | * 42 | * @return boolean 正常加载返回true 43 | */ 44 | public function autoload($class) { 45 | if (0 !== strpos($class, self::PREFIX)) { 46 | return false; 47 | } 48 | 49 | if (file_exists($file = $this->_dir . '/' . str_replace('\\', '/', $class) . '.php')) { 50 | require_once $file; 51 | 52 | return true; 53 | } 54 | 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/Base.php: -------------------------------------------------------------------------------- 1 | init($accessToken); 27 | } 28 | } 29 | 30 | /** 31 | * 配置参数 32 | * 33 | * @param string $accessToken 访问接口的$accessToken 34 | */ 35 | public function init($accessToken) { 36 | $this->accessToken = $accessToken; 37 | } 38 | 39 | /** 40 | * 接口请求方法,具体接口都调用此方法进行请求 41 | * @param strin $api 42 | * @param array $params 43 | * @return string 44 | */ 45 | public function doGet($api, array $params = array()) { 46 | $res = HTTPClient::get($this->apiPrefix . $api, array_merge( 47 | $params, 48 | array('access_token' => $this->accessToken) 49 | )); 50 | 51 | if (false === $res) { 52 | $this->setError(-10, HTTPClient::getErrorMsg()); 53 | return false; 54 | } 55 | 56 | return $res; 57 | } 58 | 59 | /** 60 | * 接口请求方法,具体接口都调用此方法进行请求 61 | * @param strin $api 62 | * @param array $data post的数据 63 | * @param array $params url中构造的参数 64 | * @param bool $dataJsonEncoded post发出数据的格式是否需要json编码 默认为false表示常规,true json 65 | * @return string 66 | */ 67 | public function doPost($api, array $data = array(), array $params = array(), $dataJsonEncoded = false) { 68 | $url = $this->apiPrefix . $api . '?' . http_build_query(array_merge( 69 | $params, 70 | array('access_token' => $this->accessToken) 71 | )); 72 | 73 | $res = HTTPClient::post($url, $data, $dataJsonEncoded); 74 | 75 | if (false === $res) { 76 | $this->setError(-10, HTTPClient::getErrorMsg()); 77 | return false; 78 | } 79 | 80 | return $res; 81 | } 82 | 83 | /** 84 | * 设置错误信息 85 | * 86 | * @param string $code 错误代码 87 | * @param string $msg 错误详细信息 88 | */ 89 | public function setError($code, $msg = '') { 90 | $this->errorCode = $code; 91 | $this->errorMsg = $msg; 92 | } 93 | 94 | /** 95 | * 获取错误代码 96 | * 97 | * @return string 错误代码 98 | */ 99 | public function getErrorCode() { 100 | return $this->errorCode; 101 | } 102 | 103 | /** 104 | * 获取错误信息 105 | * 106 | * @return string 错误信息 107 | */ 108 | public function getErrorMsg() { 109 | return $this->errorMsg; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/Open/Base.php: -------------------------------------------------------------------------------- 1 | apiPrefix . '/' . self::API_AUTHORIZE 34 | . '?' . http_build_query(array( 35 | 'appid' => $appId, 36 | 'redirect_uri' => $redirectURI, 37 | 'scope' => $scopeInfo ? self::SCOPE_INFO : self::SCOPE_BASE, 38 | 'response_type' => 'code', 39 | 'state' => $state 40 | )); 41 | } 42 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/QY/OAuth2.php: -------------------------------------------------------------------------------- 1 | setError('参数错误!'); 24 | 25 | return false; 26 | } 27 | 28 | $params = array( 29 | 'corp_id' => $corpId, 30 | 'redirect_uri' => urlencode($redirectUri), 31 | 'state' => $state 32 | ); 33 | 34 | $url = self::URL . '?' . http_build_query($params); 35 | 36 | return $url; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/QYAPI/AccessToken.php: -------------------------------------------------------------------------------- 1 | get($corpId, $corpSecret); 10 | * @package timecheer.weixin.qyapi 11 | */ 12 | class AccessToekn { 13 | 14 | const API_GET_TOKEN = '/gettoken'; 15 | 16 | protected $corpId = ''; 17 | protected $corpSecret = ''; 18 | 19 | protected $errorCode; 20 | protected $errorMsg; 21 | 22 | /** 23 | * 构造函数、配置企业号相关参数 24 | * @param string $corpId 企业号corp_id 25 | * @param string $corpSecret 企业号corp_secrect 26 | */ 27 | public function __construct($corpId = '', $corpSecret = '') { 28 | $this->init($corpId, $corpSecret); 29 | } 30 | 31 | /** 32 | * 配置企业号相关参数 33 | * 34 | * @param string $corpId 企业号corp_id 35 | * @param string $corpSecret 企业号corp_secrect 36 | */ 37 | public function init($corpId, $corpSecret) { 38 | $this->setCorpId($corpId); 39 | $this->setCorpSecret($corpSecret); 40 | } 41 | 42 | public function setCorpId($corpId) { 43 | if ($corpId) { 44 | $this->corpId = $corpId; 45 | } 46 | } 47 | 48 | public function setCorpSecret($corpSecret) { 49 | if ($corpSecret) { 50 | $this->corpSecret = $corpSecret; 51 | } 52 | } 53 | 54 | public function getCorpId() { 55 | return $this->corpId; 56 | } 57 | 58 | public function getCorpSecret() { 59 | return $this->corpSecret; 60 | } 61 | 62 | /** 63 | * 设置错误信息 64 | * 65 | * @param string $code 错误代码 66 | * @param string $msg 错误详细信息 67 | */ 68 | public function setError($code, $msg = null) { 69 | $this->errorCode = $code; 70 | $this->errorMsg = $msg; 71 | } 72 | 73 | /** 74 | * 获取错误代码 75 | * 76 | * @return string 错误代码 77 | */ 78 | public function getErrorCode() { 79 | return $this->errorCode; 80 | } 81 | 82 | /** 83 | * 获取错误信息 84 | * 85 | * @return string 错误信息 86 | */ 87 | public function getErrorMsg() { 88 | return $this->errorMsg; 89 | } 90 | 91 | /** 92 | * AccessToken需要用CorpID和Secret来换取,不同的Secret会返回不同的AccessToken。 93 | * 正常情况下AccessToken有效期为7200秒,有效期内重复获取返回相同结果; 94 | * 有效期内有接口交互(包括获取AccessToken的接口),会自动续期 95 | * @return string|boolean 96 | */ 97 | public function get($corpId = '', $corpSecret = '') { 98 | $this->init($corpId, $corpSecret); 99 | 100 | $res = $this->request(self::API_GET_TOKEN, array( 101 | 'corpid' => $this->corpId, 102 | 'corpsecret' => $this->corpSecrect, 103 | )); 104 | 105 | if(empty($res['access_token'])) { 106 | $this->setError(-11, '无效AccessToken!'); 107 | return false; 108 | } 109 | 110 | return $res['access_token']; 111 | } 112 | 113 | public function request($api, $params = array()) { 114 | $res = \TimeCheer\Weixin\Util\HTTPClient::get($api, $params); 115 | 116 | if (false === $res) { 117 | $this->setError(-10, '接口请求失败!'); 118 | return false; 119 | } 120 | 121 | return $res; 122 | } 123 | } -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/QYAPI/Agent.php: -------------------------------------------------------------------------------- 1 | setError('agentid 错误!'); 27 | 28 | return false; 29 | } 30 | 31 | return $this->doGet(self::API_AGENT_GET, array('agentid' => $agentid)); 32 | } 33 | 34 | /** 35 | * 根据应用ID s设置应用信息 36 | * 37 | * @param int $agentid 应用id 38 | * @param array $data 想要设置的信息 39 | * 40 | * @return array 41 | */ 42 | public function set($agentid, $data) { 43 | if (!is_numeric($agentid)) { 44 | $this->setError('agentid 错误!'); 45 | 46 | return false; 47 | } 48 | 49 | return $this->doPost(self::API_AGENT_SET, $data, array('agentid' => $agentid)); 50 | } 51 | 52 | /** 53 | * 企业号应用的基本信息,包括头像、昵称、帐号类型、认证类型、可见范围等信息 54 | * 55 | * @return array 56 | */ 57 | public function getAppList() { 58 | 59 | return $this->doGet(self::API_AGENT_LIST); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/TimeCheer/Weixin/QYAPI/Base.php: -------------------------------------------------------------------------------- 1 | 8 | *