__getToken(); $headers = array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $token, ); if(in_array($method,array('edi.request.accountsettlement.getlist','edi.request.reship.query','edi.request.refundinfo.detail','edi.request.shippackage.detail'))){ $headers['X-API-VERSION'] = '2.0'; } $params['headers'] = $headers; return $params; } /** * __getToken * @return mixed 返回值 */ public function __getToken() { $username = $this->__channelObj->edi['config']['ediwsuser']; $pwd = $this->__channelObj->edi['config']['ediwspwd']; $tokenKey = 'edi_'.$username; $token = cachecore::fetch($tokenKey); if($token){ return $token; } $pwd = urlencode(base64_encode(sha1($pwd,true))); $query_params = array( 'username' => $username, 'password' => $pwd, ); $url = 'https://ediws.jd.com/services/auth/user?'; $headers = array( 'Content-Type' => "application/json; charset=UTF-8", ); $httpLib = kernel::single('base_httpclient'); foreach ($query_params as $k => $v){ $arg[] = $k.'='.$v; } $url .= implode('&',$arg); $params = array(); $res = $httpLib->get($url, $headers); if(!$res){ throw new Exception("token请求错误"); } $res = json_decode($res,1); if(!$res || $res['result']!='Success' || !$res['token']){ $errMsg = sprintf('token请求错误,错误代码:%s,错误详情:%s', $res['code'], $res['message']); throw new Exception($errMsg); } $token = $res['token']; cachecore::store($tokenKey, $token, $res['data']['ttl']-600); return $token; } /** * format * @param mixed $query_params 参数 * @return mixed 返回值 */ public function format($query_params){ unset($query_params['method']); //过滤同步日志单据号 unset($query_params['original_bn'],$query_params['sign']); return json_encode($query_params); } }