commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* LICENSE 相关函数库 |
|
5 |
*/ |
|
6 |
|
|
7 |
if (!defined('IN_ECS')) |
|
8 |
{ |
|
9 |
die('Hacking attempt'); |
|
10 |
} |
|
11 |
|
|
12 |
/** |
|
13 |
* 获得网店 license 信息 |
|
14 |
* |
|
15 |
* @access public |
|
16 |
* @param integer $size |
|
17 |
* |
|
18 |
* @return array |
|
19 |
*/ |
|
20 |
function get_shop_license() |
|
21 |
{ |
|
22 |
// 取出网店 license |
|
23 |
$sql = "SELECT code, value |
|
24 |
FROM " . $GLOBALS['ecs']->table('shop_config') . " |
|
25 |
WHERE code IN ('certificate_id', 'token', 'certi') |
|
26 |
LIMIT 0,3"; |
|
27 |
$license_info = $GLOBALS['db']->getAll($sql); |
|
28 |
$license_info = is_array($license_info) ? $license_info : array(); |
|
29 |
$license = array(); |
|
30 |
foreach ($license_info as $value) |
|
31 |
{ |
|
32 |
$license[$value['code']] = $value['value']; |
|
33 |
} |
|
34 |
|
|
35 |
return $license; |
|
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* 功能:生成certi_ac验证字段 |
|
40 |
* @param string POST传递参数 |
|
41 |
* @param string 证书token |
|
42 |
* @return string |
|
43 |
*/ |
|
44 |
function make_shopex_ac($post_params, $token) |
|
45 |
{ |
|
46 |
if (!is_array($post_params)) |
|
47 |
{ |
|
48 |
return; |
|
49 |
} |
|
50 |
|
|
51 |
// core |
|
52 |
ksort($post_params); |
|
53 |
$str = ''; |
|
54 |
foreach($post_params as $key=>$value){ |
|
55 |
if($key != 'certi_ac') |
|
56 |
{ |
|
57 |
$str .= $value; |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
return md5($str . $token); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 功能:交换数据 |
|
66 |
* |
|
67 |
* @param array $certi 登录参数 |
|
68 |
* @param array $license 网店license信息 |
|
69 |
* @param bool $use_lib 使用哪一个json库,0为ec,1为shopex |
|
70 |
* @return array |
|
71 |
*/ |
|
72 |
function exchange_shop_license($certi, $license, $use_lib = 0) |
|
73 |
{ |
|
74 |
if (!is_array($certi)) |
|
75 |
{ |
|
76 |
return array(); |
|
77 |
} |
|
78 |
|
|
79 |
include_once(ROOT_PATH . 'includes/cls_transport.php'); |
|
80 |
include_once(ROOT_PATH . 'includes/cls_json.php'); |
|
81 |
|
|
82 |
$params = ''; |
|
83 |
foreach ($certi as $key => $value) |
|
84 |
{ |
|
85 |
$params .= '&' . $key . '=' . $value; |
|
86 |
} |
|
87 |
$params = trim($params, '&'); |
|
88 |
|
|
89 |
$transport = new transport; |
|
90 |
//$transport->connect_timeout = 1; |
|
91 |
$request = $transport->request($license['certi'], $params, 'POST'); |
|
92 |
$request_str = json_str_iconv($request['body']); |
|
93 |
|
|
94 |
if (empty($use_lib)) |
|
95 |
{ |
|
96 |
$json = new JSON(); |
|
97 |
$request_arr = $json->decode($request_str, 1); |
|
98 |
} |
|
99 |
else |
|
100 |
{ |
|
101 |
include_once(ROOT_PATH . 'includes/shopex_json.php'); |
|
102 |
$request_arr = json_decode($request_str, 1); |
|
103 |
} |
|
104 |
|
|
105 |
return $request_arr; |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* 功能:处理登录返回结果 |
|
110 |
* |
|
111 |
* @param array $cert_auth 登录返回的用户信息 |
|
112 |
* @return array |
|
113 |
*/ |
|
114 |
function process_login_license($cert_auth) |
|
115 |
{ |
|
116 |
if (!is_array($cert_auth)) |
|
117 |
{ |
|
118 |
return array(); |
|
119 |
} |
|
120 |
|
|
121 |
$cert_auth['auth_str'] = trim($cert_auth['auth_str']); |
|
122 |
if (!empty($cert_auth['auth_str'])) |
|
123 |
{ |
|
124 |
$cert_auth['auth_str'] = $GLOBALS['_LANG']['license_' . $cert_auth['auth_str']]; |
|
125 |
} |
|
126 |
|
|
127 |
$cert_auth['auth_type'] = trim($cert_auth['auth_type']); |
|
128 |
if (!empty($cert_auth['auth_type'])) |
|
129 |
{ |
|
130 |
$cert_auth['auth_type'] = $GLOBALS['_LANG']['license_' . $cert_auth['auth_type']]; |
|
131 |
} |
|
132 |
|
|
133 |
return $cert_auth; |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* 功能:license 登录 |
|
138 |
* |
|
139 |
* @param array $certi_added 配置信息补充数组 array_key 登录信息的key;array_key => array_value; |
|
140 |
* @return array $return_array['flag'] = login_succ、login_fail、login_ping_fail、login_param_fail; |
|
141 |
* $return_array['request']; |
|
142 |
*/ |
|
143 |
function license_login($certi_added = '') |
|
144 |
{ |
|
145 |
// 登录信息配置 |
|
146 |
$certi['certi_app'] = ''; // 证书方法 |
|
147 |
$certi['app_id'] = 'ecshop_b2c'; // 说明客户端来源 |
|
148 |
$certi['app_instance_id'] = ''; // 应用服务ID |
|
149 |
$certi['version'] = LICENSE_VERSION; // license接口版本号 |
|
150 |
$certi['shop_version'] = VERSION . '#' . RELEASE; // 网店软件版本号 |
|
151 |
$certi['certi_url'] = sprintf($GLOBALS['ecs']->url()); // 网店URL |
|
152 |
$certi['certi_session'] = $GLOBALS['sess']->get_session_id(); // 网店SESSION标识 |
|
153 |
$certi['certi_validate_url'] = sprintf($GLOBALS['ecs']->url() . 'certi.php'); // 网店提供于官方反查接口 |
|
154 |
$certi['format'] = 'json'; // 官方返回数据格式 |
|
155 |
$certi['certificate_id'] = ''; // 网店证书ID |
|
156 |
// 标识 |
|
157 |
$certi_back['succ'] = 'succ'; |
|
158 |
$certi_back['fail'] = 'fail'; |
|
159 |
// return 返回数组 |
|
160 |
$return_array = array(); |
|
161 |
|
|
162 |
if (is_array($certi_added)) |
|
163 |
{ |
|
164 |
foreach ($certi_added as $key => $value) |
|
165 |
{ |
|
166 |
$certi[$key] = $value; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
// 取出网店 license |
|
171 |
$license = get_shop_license(); |
|
172 |
|
|
173 |
// 检测网店 license |
|
174 |
if (!empty($license['certificate_id']) && !empty($license['token']) && !empty($license['certi'])) |
|
175 |
{ |
|
176 |
// 登录 |
|
177 |
$certi['certi_app'] = 'certi.login'; // 证书方法 |
|
178 |
$certi['app_instance_id'] = 'cert_auth'; // 应用服务ID |
|
179 |
$certi['certificate_id'] = $license['certificate_id']; // 网店证书ID |
|
180 |
$certi['certi_ac'] = make_shopex_ac($certi, $license['token']); // 网店验证字符串 |
|
181 |
|
|
182 |
$request_arr = exchange_shop_license($certi, $license); |
|
183 |
if (is_array($request_arr) && $request_arr['res'] == $certi_back['succ']) |
|
184 |
{ |
|
185 |
$return_array['flag'] = 'login_succ'; |
|
186 |
$return_array['request'] = $request_arr; |
|
187 |
} |
|
188 |
elseif (is_array($request_arr) && $request_arr['res'] == $certi_back['fail']) |
|
189 |
{ |
|
190 |
$return_array['flag'] = 'login_fail'; |
|
191 |
$return_array['request'] = $request_arr; |
|
192 |
} |
|
193 |
else |
|
194 |
{ |
|
195 |
$return_array['flag'] = 'login_ping_fail'; |
|
196 |
$return_array['request'] = array('res' => 'fail'); |
|
197 |
} |
|
198 |
} |
|
199 |
else |
|
200 |
{ |
|
201 |
$return_array['flag'] = 'login_param_fail'; |
|
202 |
$return_array['request'] = array('res' => 'fail'); |
|
203 |
} |
|
204 |
|
|
205 |
return $return_array; |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* 功能:license 注册 |
|
210 |
* |
|
211 |
* @param array $certi_added 配置信息补充数组 array_key 登录信息的key;array_key => array_value; |
|
212 |
* @return array $return_array['flag'] = reg_succ、reg_fail、reg_ping_fail; |
|
213 |
* $return_array['request']; |
|
214 |
*/ |
|
215 |
function license_reg($certi_added = '') |
|
216 |
{ |
|
217 |
// 登录信息配置 |
|
218 |
$certi['certi_app'] = ''; // 证书方法 |
|
219 |
$certi['app_id'] = 'ecshop_b2c'; // 说明客户端来源 |
|
220 |
$certi['app_instance_id'] = ''; // 应用服务ID |
|
221 |
$certi['version'] = LICENSE_VERSION; // license接口版本号 |
|
222 |
$certi['shop_version'] = VERSION . '#' . RELEASE; // 网店软件版本号 |
|
223 |
$certi['certi_url'] = sprintf($GLOBALS['ecs']->url()); // 网店URL |
|
224 |
$certi['certi_session'] = $GLOBALS['sess']->get_session_id(); // 网店SESSION标识 |
|
225 |
$certi['certi_validate_url'] = sprintf($GLOBALS['ecs']->url() . 'certi.php'); // 网店提供于官方反查接口 |
|
226 |
$certi['format'] = 'json'; // 官方返回数据格式 |
|
227 |
$certi['certificate_id'] = ''; // 网店证书ID |
|
228 |
// 标识 |
|
229 |
$certi_back['succ'] = 'succ'; |
|
230 |
$certi_back['fail'] = 'fail'; |
|
231 |
// return 返回数组 |
|
232 |
$return_array = array(); |
|
233 |
|
|
234 |
if (is_array($certi_added)) |
|
235 |
{ |
|
236 |
foreach ($certi_added as $key => $value) |
|
237 |
{ |
|
238 |
$certi[$key] = $value; |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
// 取出网店 license |
|
243 |
$license = get_shop_license(); |
|
244 |
|
|
245 |
// 注册 |
|
246 |
$certi['certi_app'] = 'certi.reg'; // 证书方法 |
|
247 |
$certi['certi_ac'] = make_shopex_ac($certi, ''); // 网店验证字符串 |
|
248 |
unset($certi['certificate_id']); |
|
249 |
|
|
250 |
$request_arr = exchange_shop_license($certi, $license); |
|
251 |
if (is_array($request_arr) && $request_arr['res'] == $certi_back['succ']) |
|
252 |
{ |
|
253 |
// 注册信息入库 |
|
254 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('shop_config') . " |
|
255 |
SET value = '" . $request_arr['info']['certificate_id'] . "' WHERE code = 'certificate_id'"; |
|
256 |
$GLOBALS['db']->query($sql); |
|
257 |
$sql = "UPDATE " . $GLOBALS['ecs']->table('shop_config') . " |
|
258 |
SET value = '" . $request_arr['info']['token'] . "' WHERE code = 'token'"; |
|
259 |
$GLOBALS['db']->query($sql); |
|
260 |
|
|
261 |
$return_array['flag'] = 'reg_succ'; |
|
262 |
$return_array['request'] = $request_arr; |
|
263 |
} |
|
264 |
elseif (is_array($request_arr) && $request_arr['res'] == $certi_back['fail']) |
|
265 |
{ |
|
266 |
$return_array['flag'] = 'reg_fail'; |
|
267 |
$return_array['request'] = $request_arr; |
|
268 |
} |
|
269 |
else |
|
270 |
{ |
|
271 |
$return_array['flag'] = 'reg_ping_fail'; |
|
272 |
$return_array['request'] = array('res' => 'fail'); |
|
273 |
} |
|
274 |
|
|
275 |
return $return_array; |
|
276 |
} |
|
277 |
?> |