Skip to content

Commit b47069c

Browse files
committedSep 24, 2020
[UPD] 优化
1 parent b3b3a2e commit b47069c

12 files changed

+730
-6
lines changed
 

‎composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"minimum-stability": "dev",
2121
"autoload": {
2222
"psr-4": {
23-
"Mpcube\\Wechat\\": "src/Wechat",
24-
"Mpcube\\Alipay\\": "src/Alipay"
23+
"Mpcube\\": "src"
2524
}
2625
},
2726
"repositories": {

‎src/Common/Cache.php

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace Mpcube\Common;
4+
5+
use Doctrine\Common\Cache\FilesystemCache;
6+
use Doctrine\Common\Cache\MemcacheCache;
7+
use Doctrine\Common\Cache\RedisCache;
8+
9+
trait Cache
10+
{
11+
protected $cache_driver_current = self::CACHE_DRIVER_FILESYSTEM;
12+
protected $cache_driver_list = array(self::CACHE_DRIVER_FILESYSTEM, self::CACHE_DRIVER_MEMECACHE, self::CACHE_DRIVER_REDIS);
13+
14+
private $_file_path = '';
15+
private $_redis_conn = null;
16+
private $_memecache_conn = null;
17+
18+
private $_cache = null;
19+
20+
public function setCacheDriver($driver='Filesystem')
21+
{
22+
if (in_array($driver, $this->cache_driver_list)) {
23+
$this->cache_driver_current = $driver;
24+
return $this;
25+
}
26+
27+
return false;
28+
}
29+
30+
public function getCacheDriver()
31+
{
32+
return $this->cache_driver_current;
33+
}
34+
35+
public function setFilePath($rel_path='cache/wechat')
36+
{
37+
if ($this->getCacheDriver()==self::CACHE_DRIVER_FILESYSTEM) {
38+
39+
$this->_file_path = Runtime::getInstance()->dir.$rel_path;
40+
$this->_cache = new FilesystemCache($this->_file_path);
41+
42+
return $this;
43+
}
44+
45+
return false;
46+
}
47+
48+
public function setRedisConn($host='', $port='', $password='', $timeout=0.0)
49+
{
50+
if ($this->getCacheDriver()==self::CACHE_DRIVER_REDIS) {
51+
52+
$redis = new \Redis();
53+
$redis->connect($host, $port, $timeout);
54+
if (!empty($password)) {
55+
$redis->auth($password);
56+
}
57+
$this->_cache = new RedisCache();
58+
$this->_cache->setRedis($redis);
59+
60+
return $this;
61+
}
62+
63+
return false;
64+
}
65+
66+
public function setMemecacheConn($host='', $port='11211')
67+
{
68+
if ($this->getCacheDriver()==self::CACHE_DRIVER_MEMECACHE) {
69+
70+
$memcache = new \Memcache();
71+
$memcache->connect($host, $port);
72+
73+
$this->_cache = new MemcacheCache();
74+
$this->_cache->setMemcache($memcache);
75+
76+
return $this;
77+
}
78+
79+
return false;
80+
}
81+
}

‎src/Common/Common.php

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
<?php
2+
3+
namespace Mpcube\Common;
4+
5+
trait Common
6+
{
7+
private $WechatApiBaseURL = 'https://api.weixin.qq.com/';
8+
private $WechatMpBaseURL = 'https://mp.weixin.qq.com/';
9+
private $WxworkApiBaseURL = 'https://qyapi.weixin.qq.com/';
10+
private $access_token = '';
11+
12+
public function setAccessToken($access_token)
13+
{
14+
$this->access_token = $access_token;
15+
return $this;
16+
}
17+
18+
private function httpRespToArray($resp='', array $params_remark_req=array(), array $params_remark_res=array())
19+
{
20+
$arr = Errcode::parseErrcodeByString($resp);
21+
22+
if (!empty($params_remark_req)) {
23+
$arr['_remark']['fields']['request'] = $params_remark_req;
24+
}
25+
26+
if (!empty($params_remark_res)) {
27+
$arr['_remark']['fields']['response'] = $params_remark_res;
28+
}
29+
30+
return $arr;
31+
}
32+
33+
// region curl工具函数
34+
35+
private function curlGet($url)
36+
{
37+
//初始化
38+
$ch = curl_init();
39+
40+
//设置抓取的url
41+
curl_setopt($ch, CURLOPT_URL, $url);
42+
43+
//设置头文件的信息作为数据流输出
44+
//curl_setopt($ch, CURLOPT_HEADER, 1);
45+
46+
//忽略SSL验证
47+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
48+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
49+
50+
//设置获取的信息以文件流的形式返回,而不是直接输出。
51+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
52+
53+
//执行命令
54+
$data = curl_exec($ch);
55+
56+
//错误提示
57+
if (curl_errno($ch)) {
58+
print curl_error($ch);
59+
}
60+
61+
//关闭URL请求
62+
curl_close($ch);
63+
64+
//显示获得的数据
65+
return $data;
66+
}
67+
68+
private function curlPost($url, array $post_data)
69+
{
70+
//初始化
71+
$ch = curl_init();
72+
73+
//设置抓取的url
74+
curl_setopt($ch, CURLOPT_URL, $url);
75+
76+
//设置头文件的信息作为数据流输出
77+
//curl_setopt($ch, CURLOPT_HEADER, 1);
78+
79+
//忽略SSL验证
80+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
81+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
82+
83+
//设置获取的信息以文件流的形式返回,而不是直接输出。
84+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
85+
86+
//设置post方式提交
87+
curl_setopt($ch, CURLOPT_POST, 1);
88+
89+
//设置post数据
90+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data, JSON_UNESCAPED_UNICODE));
91+
92+
//执行命令
93+
$data = curl_exec($ch);
94+
95+
//错误提示
96+
if (curl_errno($ch)) {
97+
print curl_error($ch);
98+
}
99+
100+
//关闭URL请求
101+
curl_close($ch);
102+
103+
//显示获得的数据
104+
return $data;
105+
}
106+
107+
private function curlPostWxMedia($url, $full_file_path, array $extra_field=array(), $file_field='media')
108+
{
109+
//初始化
110+
$ch = curl_init();
111+
112+
//设置抓取的url
113+
curl_setopt($ch, CURLOPT_URL, $url);
114+
115+
//告知php是容忍还是禁止旧的@语法
116+
curl_setopt ($ch, CURLOPT_SAFE_UPLOAD, false);
117+
118+
//设置头文件的信息作为数据流输出
119+
//curl_setopt($ch, CURLOPT_HEADER, 1);
120+
121+
//忽略SSL验证
122+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
123+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
124+
125+
//设置获取的信息以文件流的形式返回,而不是直接输出。
126+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
127+
128+
//设置post方式提交
129+
curl_setopt($ch, CURLOPT_POST, 1);
130+
131+
//post数据,使用@符号,curl就会认为是有文件上传
132+
$post_data = array($file_field=>new \CURLFile(realpath($full_file_path)));
133+
134+
//如果需要加入其他字段
135+
if ($extra_field) {
136+
$post_data = array_merge($post_data, $extra_field);
137+
}
138+
139+
//设置post数据
140+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
141+
142+
//执行命令
143+
$data = curl_exec($ch);
144+
145+
//错误提示
146+
if (curl_errno($ch)) {
147+
print curl_error($ch);
148+
}
149+
150+
//关闭URL请求
151+
curl_close($ch);
152+
153+
//显示获得的数据
154+
return $data;
155+
}
156+
157+
158+
// public function saveMediaToServer($url)
159+
// {
160+
// // 要存在你服务器哪个位置?
161+
// $savePathFile = '/' . date('YmdHis') . '.jpg';
162+
// $targetName = $savePathFile;
163+
// $ch = curl_init();
164+
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
165+
// $fp = fopen($targetName, 'wb');
166+
// curl_setopt($ch, CURLOPT_URL, $url);
167+
// curl_setopt($ch, CURLOPT_FILE, $fp);
168+
// curl_setopt($ch, CURLOPT_HEADER, 0);
169+
// curl_exec($ch);
170+
// curl_close($ch);
171+
// fclose($fp);
172+
//
173+
// return PubCommon::serverDomain() . $savePathFile;
174+
// }
175+
176+
// endregion
177+
178+
}

‎src/Common/MagicGetSet.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Mpcube\Common;
4+
5+
trait MagicGetSet
6+
{
7+
public function __get($name)
8+
{
9+
if(property_exists($this, $name)) {
10+
return $this->$name;
11+
}
12+
13+
return null;
14+
}
15+
16+
public function __set($name, $value)
17+
{
18+
if(property_exists($this, $name)) {
19+
$this->$name = $value;
20+
}
21+
}
22+
23+
public function __isset($name)
24+
{
25+
if(property_exists($this, $name)) {
26+
return true;
27+
}
28+
29+
return false;
30+
}
31+
32+
}

‎src/Common/Runtime.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: FRANK
5+
* Date: 2019/7/11
6+
* Time: 12:27
7+
*/
8+
9+
namespace Mpcube\Common;
10+
11+
12+
class Runtime
13+
{
14+
use Singleton, MagicGetSet;
15+
16+
protected $dir = __DIR__.'../../../runtime/';
17+
18+
}

‎src/Common/Singleton.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Mpcube\Common;
4+
5+
trait Singleton
6+
{
7+
// region 单例
8+
9+
private static $_instance = null;
10+
11+
private function __construct()
12+
{
13+
}
14+
15+
private function __clone()
16+
{
17+
// TODO: Implement __clone() method.
18+
}
19+
20+
public static function getInstance()
21+
{
22+
if (self::$_instance == null) {
23+
self::$_instance = new static();
24+
}
25+
26+
return self::$_instance;
27+
}
28+
// endregion
29+
30+
}

‎src/Wechat/Publics/Cache.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ public function getCacheDriver()
3434
return $this->cache_driver_current;
3535
}
3636

37-
public function setFilePath($rel_path='cache/wechat')
37+
public function setFilePath($rel_path='')
3838
{
3939
if ($this->getCacheDriver()==self::CACHE_DRIVER_FILESYSTEM) {
4040

41-
$this->_file_path = Runtime::getInstance()->dir.$rel_path;
41+
if (empty($rel_path)) {
42+
$this->_file_path = Runtime::getInstance()->dir.'cache/wechat';
43+
} else {
44+
$this->_file_path = $rel_path;
45+
}
4246
$this->_cache = new FilesystemCache($this->_file_path);
4347

4448
return $this;

‎src/Wechat/Publics/Web/JssdkConfig.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class JssdkConfig
88
{
99
use Common, Singleton;
1010

11-
public function getSignPackage($appid, $jsapiTicket)
11+
public function getSignPackage($appid, $jsapiTicket, $url=null)
1212
{
1313
// 注意 URL 一定要动态获取,不能 hardcode.
14-
$url = $_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
14+
if (empty($url)) {
15+
$url = $_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];;
16+
}
1517

1618
$timestamp = time();
1719
$nonceStr = $this->createNonceStr();

‎src/Wxwork/Internal/AccessToken.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Mpcube\Wxwork\Internal;
4+
5+
use Mpcube\Common\Cache;
6+
use Mpcube\Common\Common;
7+
use Mpcube\Common\Singleton;
8+
9+
class AccessToken
10+
{
11+
use Common, Singleton, Cache;
12+
13+
const CACHE_DRIVER_FILESYSTEM = 'Filesystem';
14+
const CACHE_DRIVER_MEMECACHE = 'Memecache';
15+
const CACHE_DRIVER_REDIS = 'Redis';
16+
17+
public function getToken($corpid, $agentid, $corpsecret)
18+
{
19+
$arr = json_decode($this->_cache->fetch("{$corpid}_{$agentid}_access_token"), true);
20+
21+
if (!is_array($arr) || (isset($arr['next_time']) && (time()>$arr['next_time']))) {
22+
$url = $this->WxworkApiBaseURL."cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}";
23+
$arr = json_decode($this->curlGet($url), true);
24+
$arr['next_time'] = time() + ceil($arr['expires_in'] * 2 / 3);
25+
$this->_cache->save("{$corpid}_{$agentid}_access_token", json_encode($arr));
26+
}
27+
28+
return $arr['access_token'];
29+
}
30+
}

‎src/Wxwork/Internal/Errcode.php

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<?php
2+
3+
namespace Mpcube\Wxwork\Internal;
4+
5+
class Errcode
6+
{
7+
private static $_errcode = array(
8+
-1 => '系统繁忙,此时请开发者稍候再试',
9+
0 => '请求成功',
10+
40001 => '获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口',
11+
40002 => '不合法的凭证类型',
12+
40003 => '不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID',
13+
40004 => '不合法的媒体文件类型',
14+
40005 => '不合法的文件类型',
15+
40006 => '不合法的文件大小',
16+
40007 => '不合法的媒体文件 id',
17+
40008 => '不合法的消息类型',
18+
40009 => '不合法的图片文件大小',
19+
40010 => '不合法的语音文件大小',
20+
40011 => '不合法的视频文件大小',
21+
40012 => '不合法的缩略图文件大小',
22+
40013 => '不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写',
23+
40014 => '不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口',
24+
40015 => '不合法的菜单类型',
25+
40016 => '不合法的按钮个数',
26+
40017 => '不合法的按钮个数',
27+
40018 => '不合法的按钮名字长度',
28+
40019 => '不合法的按钮 KEY 长度',
29+
40020 => '不合法的按钮 URL 长度',
30+
40021 => '不合法的菜单版本号',
31+
40022 => '不合法的子菜单级数',
32+
40023 => '不合法的子菜单按钮个数',
33+
40024 => '不合法的子菜单按钮类型',
34+
40025 => '不合法的子菜单按钮名字长度',
35+
40026 => '不合法的子菜单按钮 KEY 长度',
36+
40027 => '不合法的子菜单按钮 URL 长度',
37+
40028 => '不合法的自定义菜单使用用户',
38+
40029 => '无效的 oauth_code',
39+
40030 => '不合法的 refresh_token',
40+
40031 => '不合法的 openid 列表',
41+
40032 => '不合法的 openid 列表长度',
42+
40033 => '不合法的请求字符,不能包含 \uxxxx 格式的字符',
43+
40035 => '不合法的参数',
44+
40038 => '不合法的请求格式',
45+
40039 => '不合法的 URL 长度',
46+
40048 => '无效的url',
47+
40050 => '不合法的分组 id',
48+
40051 => '分组名字不合法',
49+
40060 => '删除单篇图文时,指定的 article_idx 不合法',
50+
40117 => '分组名字不合法',
51+
40118 => 'media_id 大小不合法',
52+
40119 => 'button 类型错误',
53+
40120 => 'button 类型错误',
54+
40121 => '不合法的 media_id 类型',
55+
40125 => '无效的appsecret',
56+
40132 => '微信号不合法',
57+
40137 => '不支持的图片格式',
58+
40155 => '请勿添加其他公众号的主页链接',
59+
40163 => 'oauth_code已使用',
60+
40201 => '不正确的URL,一般是开发者未设置回调URL。',
61+
40202 => '不正确的action',
62+
40203 => '不正确的check_operator',
63+
41001 => '缺少 access_token 参数',
64+
41002 => '缺少 appid 参数',
65+
41003 => '缺少 refresh_token 参数',
66+
41004 => '缺少 secret 参数',
67+
41005 => '缺少多媒体文件数据',
68+
41006 => '缺少 media_id 参数',
69+
41007 => '缺少子菜单数据',
70+
41008 => '缺少 oauth code',
71+
41009 => '缺少 openid',
72+
42001 => 'access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明',
73+
42002 => 'refresh_token 超时',
74+
42003 => 'oauth_code 超时',
75+
42007 => '用户修改微信密码, accesstoken 和 refreshtoken 失效,需要重新授权',
76+
43001 => '需要 GET 请求',
77+
43002 => '需要 POST 请求',
78+
43003 => '需要 HTTPS 请求',
79+
43004 => '需要接收者关注',
80+
43005 => '需要好友关系',
81+
43008 => '商户没有开通微信支付权限或者没有在商户后台申请微信买单功能;',
82+
43019 => '需要将接收者从黑名单中移除',
83+
44001 => '多媒体文件为空',
84+
44002 => 'POST 的数据包为空',
85+
44003 => '图文消息内容为空',
86+
44004 => '文本消息内容为空',
87+
45001 => '多媒体文件大小超过限制',
88+
45002 => '消息内容超过限制',
89+
45003 => '标题字段超过限制',
90+
45004 => '描述字段超过限制',
91+
45005 => '链接字段超过限制',
92+
45006 => '图片链接字段超过限制',
93+
45007 => '语音播放时间超过限制',
94+
45008 => '图文消息超过限制',
95+
45009 => '接口调用超过限制',
96+
45010 => '创建菜单个数超过限制',
97+
45011 => 'API 调用太频繁,请稍候再试',
98+
45015 => '回复时间超过限制',
99+
45016 => '系统分组,不允许修改',
100+
45017 => '分组名字过长',
101+
45018 => '分组数量超过上限',
102+
45046 => '该card_id已经设置了买单功能,不可变更为自助核销功能,设置冲突',
103+
45047 => '客服接口下行条数超过上限',
104+
45056 => '创建的标签数过多,请注意不能超过100个',
105+
45057 => '该标签下粉丝数超过10w,不允许直接删除',
106+
45058 => '不能修改0/1/2这三个系统默认保留的标签',
107+
45059 => '有粉丝身上的标签数已经超过限制,即超过20个',
108+
45072 => 'command字段取值不对',
109+
45080 => '下发输入状态,需要之前30秒内跟用户有过消息交互',
110+
45081 => '已经在输入状态,不可重复下发',
111+
45157 => '标签名非法,请注意不能和其他标签重名',
112+
45158 => '标签名长度超过30个字节',
113+
45159 => '非法的tag_id',
114+
46001 => '不存在媒体数据',
115+
46002 => '不存在的菜单版本',
116+
46003 => '不存在的菜单数据',
117+
46004 => '不存在的用户',
118+
47001 => '解析 JSON/XML 内容错误',
119+
48001 => 'api 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限',
120+
48002 => '粉丝拒收消息(粉丝在公众号选项中,关闭了 “ 接收消息 ” )',
121+
48004 => 'api 接口被封禁,请登录 mp.weixin.qq.com 查看详情',
122+
48005 => 'api 禁止删除被自动回复和自定义菜单引用的素材',
123+
48006 => 'api 禁止清零调用次数,因为清零次数达到上限',
124+
48008 => '没有该类型消息的发送权限',
125+
49003 => '传入的openid不属于此AppID',
126+
50001 => '用户未授权该 api',
127+
50002 => '用户受限,可能是违规后接口被封禁',
128+
50005 => '用户未关注公众号',
129+
61451 => '参数错误 (invalid parameter)',
130+
61452 => '无效客服账号 (invalid kf_account)',
131+
61453 => '客服帐号已存在 (kf_account exsited)',
132+
61454 => '客服帐号名长度超过限制 ( 仅允许 10 个英文字符,不包括 @ 及 @ 后的公众号的微信号 )(invalid kf_acount length)',
133+
61455 => '客服帐号名包含非法字符 ( 仅允许英文 + 数字 )(illegal character in kf_account)',
134+
61456 => '客服帐号个数超过限制 (10 个客服账号 )(kf_account count exceeded)',
135+
61457 => '无效头像文件类型 (invalid file type)',
136+
61450 => '系统错误 (system error)',
137+
61500 => '日期格式错误',
138+
63001 => '部分参数为空',
139+
63002 => '无效的签名',
140+
65301 => '不存在此 menuid 对应的个性化菜单',
141+
65302 => '没有相应的用户',
142+
65303 => '没有默认菜单,不能创建个性化菜单',
143+
65304 => 'MatchRule 信息为空',
144+
65305 => '个性化菜单数量受限',
145+
65306 => '不支持个性化菜单的帐号',
146+
65307 => '个性化菜单信息为空',
147+
65308 => '包含没有响应类型的 button',
148+
65309 => '个性化菜单开关处于关闭状态',
149+
65310 => '填写了省份或城市信息,国家信息不能为空',
150+
65311 => '填写了城市信息,省份信息不能为空',
151+
65312 => '不合法的国家信息',
152+
65313 => '不合法的省份信息',
153+
65314 => '不合法的城市信息',
154+
65316 => '该公众号的菜单设置了过多的域名外跳(最多跳转到 3 个域名的链接)',
155+
65317 => '不合法的 URL',
156+
65400 => 'API不可用,即没有开通/升级到新客服功能',
157+
65401 => '无效客服帐号',
158+
65402 => '帐号尚未绑定微信号,不能投入使用',
159+
65403 => '客服昵称不合法',
160+
65404 => '客服帐号不合法',
161+
65405 => '帐号数目已达到上限,不能继续添加',
162+
65406 => '已经存在的客服帐号',
163+
65407 => '邀请对象已经是本公众号客服',
164+
65408 => '本公众号已发送邀请给该微信号',
165+
65409 => '无效的微信号',
166+
65410 => '邀请对象绑定公众号客服数量达到上限(目前每个微信号最多可以绑定5个公众号客服帐号)',
167+
65411 => '该帐号已经有一个等待确认的邀请,不能重复邀请',
168+
65412 => '该帐号已经绑定微信号,不能进行邀请',
169+
65413 => '不存在对应用户的会话信息',
170+
65414 => '客户正在被其他客服接待',
171+
65416 => '查询参数不合法',
172+
65417 => '查询时间段超出限制',
173+
87009 => '无效的签名',
174+
9001001 => 'POST 数据参数不合法',
175+
9001002 => '远端服务不可用',
176+
9001003 => 'Ticket 不合法',
177+
9001004 => '获取摇周边用户信息失败',
178+
9001005 => '获取商户信息失败',
179+
9001006 => '获取 OpenID 失败',
180+
9001007 => '上传文件缺失',
181+
9001008 => '上传素材的文件类型不合法',
182+
9001009 => '上传素材的文件尺寸不合法',
183+
9001010 => '上传失败',
184+
9001020 => '帐号不合法',
185+
9001021 => '已有设备激活率低于 50% ,不能新增设备',
186+
9001022 => '设备申请数不合法,必须为大于 0 的数字',
187+
9001023 => '已存在审核中的设备 ID 申请',
188+
9001024 => '一次查询设备 ID 数量不能超过 50',
189+
9001025 => '设备 ID 不合法',
190+
9001026 => '页面 ID 不合法',
191+
9001027 => '页面参数不合法',
192+
9001028 => '一次删除页面 ID 数量不能超过 10',
193+
9001029 => '页面已应用在设备中,请先解除应用关系再删除',
194+
9001030 => '一次查询页面 ID 数量不能超过 50',
195+
9001031 => '时间区间不合法',
196+
9001032 => '保存设备与页面的绑定关系参数错误',
197+
9001033 => '门店 ID 不合法',
198+
9001034 => '设备备注信息过长',
199+
9001035 => '设备申请参数不合法',
200+
9001036 => '查询起始值 begin 不合法',
201+
);
202+
203+
/**
204+
* 解析错误编码
205+
* @param array $resp
206+
* @return array
207+
*/
208+
public static function parseErrcodeByArray(array $resp)
209+
{
210+
if (isset($resp['errcode']) && isset(self::$_errcode[$resp['errcode']])) {
211+
$resp['_remark']['errmsg'] = self::$_errcode[$resp['errcode']];
212+
} elseif (isset($resp['errcode'])) {
213+
$resp['_remark']['errmsg'] = '未查找到对应错误';
214+
}
215+
216+
return $resp;
217+
}
218+
219+
/**
220+
* 解析string类型错误编码
221+
* @param $respstr
222+
* @return array|bool
223+
*/
224+
public static function parseErrcodeByString($respstr)
225+
{
226+
$arr = json_decode($respstr, true);
227+
228+
if(!is_array($arr)) {
229+
return false;
230+
}
231+
232+
return self::parseErrcodeByArray($arr);
233+
}
234+
235+
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Mpcube\Wxwork\Internal\User;
3+
4+
class ParamsRemark
5+
{
6+
const USER_GET_REQ = array(
7+
'access_token' => array('required'=>'', 'memo'=>'调用接口凭据'),
8+
'userid' => array('required'=>'', 'memo'=>'成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节'),
9+
);
10+
11+
const USER_GET_RES = array(
12+
'errcode' => array('memo'=>'返回码'),
13+
'errmsg' => array('memo'=>'对返回码的文本描述内容'),
14+
'userid' => array('memo'=>'成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节'),
15+
'name' => array('memo'=>'成员名称,此字段从2019年12月30日起,对新创建第三方应用不再返回,2020年6月30日起,对所有历史第三方应用不再返回,后续第三方仅通讯录应用可获取,第三方页面需要通过通讯录展示组件来展示名字'),
16+
'mobile' => array('memo'=>'手机号码,第三方仅通讯录应用可获取'),
17+
'department' => array('memo'=>'成员所属部门id列表,仅返回该应用有查看权限的部门id'),
18+
'order' => array('memo'=>'部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。值范围是[0, 2^32)'),
19+
'position' => array('memo'=>'职务信息;第三方仅通讯录应用可获取'),
20+
'gender' => array('memo'=>'性别。0表示未定义,1表示男性,2表示女性'),
21+
'email' => array('memo'=>'邮箱,第三方仅通讯录应用可获取'),
22+
'is_leader_in_dept' => array('memo'=>'表示在所在的部门内是否为上级。;第三方仅通讯录应用可获取'),
23+
'avatar' => array('memo'=>'头像url。 第三方仅通讯录应用可获取'),
24+
'thumb_avatar' => array('memo'=>'头像缩略图url。第三方仅通讯录应用可获取'),
25+
'telephone' => array('memo'=>'座机。第三方仅通讯录应用可获取'),
26+
'enable' => array('memo'=>'成员启用状态。1表示启用的成员,0表示被禁用。注意,服务商调用接口不会返回此字段'),
27+
'alias' => array('memo'=>'别名;第三方仅通讯录应用可获取'),
28+
'extattr' => array('memo'=>'扩展属性,第三方仅通讯录应用可获取'),
29+
'status' => array('memo'=>'激活状态: 1=已激活,2=已禁用,4=未激活。已激活代表已激活企业微信或已关注微工作台(原企业号)。未激活代表既未激活企业微信又未关注微工作台(原企业号)。'),
30+
'qr_code' => array('memo'=>'员工个人二维码,扫描可添加为外部联系人(注意返回的是一个url,可在浏览器上打开该url以展示二维码);第三方仅通讯录应用可获取'),
31+
'external_profile' => array('memo'=>'成员对外属性,字段详情见对外属性;第三方仅通讯录应用可获取'),
32+
'external_position' => array('memo'=>'对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。'),
33+
'address' => array('memo'=>'地址。'),
34+
);
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
}

‎src/Wxwork/Internal/User/User.php

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Mpcube\Wxwork\Internal\User;
3+
4+
use Mpcube\Common\Common;
5+
use Mpcube\Common\Singleton;
6+
7+
class User
8+
{
9+
use Common, Singleton;
10+
11+
private $_user_list = array();
12+
13+
//读取成员
14+
public function get($userid)
15+
{
16+
$url = $this->WxworkApiBaseURL.'cgi-bin/user/get?access_token='.$this->access_token.'&userid='.$userid;
17+
var_dump($url);
18+
var_dump($this->curlGet($url));
19+
return $this->httpRespToArray($this->curlGet($url), ParamsRemark::USER_GET_REQ, ParamsRemark::USER_GET_RES);
20+
}
21+
//
22+
// //设置用户备注名
23+
// public function infoUpdateRemark($openid, $remark)
24+
// {
25+
// $url = $this->WechatApiBaseURL.'cgi-bin/user/info/updateremark?access_token='.$this->access_token;
26+
//
27+
// $arr = compact('openid', 'remark');
28+
//
29+
// return $this->httpRespToArray($this->curlPost($url, $arr), ParamsRemark::USER_INFO_UPDATEREMARK_RES);
30+
// }
31+
//
32+
// //获取用户基本信息(UnionID机制)
33+
// public function info($openid, $lang='zh_CN')
34+
// {
35+
// $url = $this->WechatApiBaseURL.'cgi-bin/user/info?access_token='.$this->access_token.'&openid='.$openid.'&lang='.$lang;
36+
// return $this->httpRespToArray($this->curlGet($url), ParamsRemark::USER_INFO_REQ, ParamsRemark::USER_INFO_RES);
37+
// }
38+
//
39+
// public function setUserList($openid, $lang='zh_CN')
40+
// {
41+
// $this->_user_list[] = compact('openid', 'lang');
42+
// return $this;
43+
// }
44+
//
45+
// public function clearUserList()
46+
// {
47+
// $this->_user_list = array();
48+
// return $this;
49+
// }
50+
//
51+
// //批量获取用户基本信息
52+
// //开发者可通过该接口来批量获取用户基本信息。最多支持一次拉取100条。
53+
// public function infoBatchGet()
54+
// {
55+
// $url = $this->WechatApiBaseURL.'cgi-bin/user/info/batchget?access_token='.$this->access_token;
56+
//
57+
// $arr = array("user_list" => $this->_user_list);
58+
//
59+
// return $this->httpRespToArray($this->curlPost($url, $arr), ParamsRemark::USER_INFO_BATCHGET_REQ, ParamsRemark::USER_INFO_BATCHGET_RES);
60+
// }
61+
//
62+
// //获取用户列表
63+
// public function get($next_openid='')
64+
// {
65+
// $url = $this->WechatApiBaseURL.'cgi-bin/user/get?access_token='.$this->access_token.'&next_openid='.$next_openid;
66+
//
67+
// return $this->httpRespToArray($this->curlGet($url), ParamsRemark::USER_GET_REQ, ParamsRemark::USER_GET_RES);
68+
// }
69+
70+
}

0 commit comments

Comments
 (0)
Please sign in to comment.