charsetToUTF8($data); $order = ''; $merchant_order = $data['tbOrderNo']; try { $redis = new redisObj(); $data = $redis->get('taobao_query' . $merchant_order); } catch (Exception) { // 处理Redis操作异常 $data = false; } $this->agentId= input('app_key'); $data = $this->queryData($merchant_order, $data, $order); return $this->yesTB($data,'query',$merchant_order); } public function query_coop() { $data = input(); $data = $this->charsetToUTF8($data); $order = ''; $merchant_order = $data['tbOrderNo']; $this->bizType = $data['bizType']; try { $redis = new redisObj(); $data = $redis->get('taobao_query' . $merchant_order); } catch (Exception) { // 处理Redis操作异常 $data = false; } $this->agentId= input('supplierId'); $data = $this->queryData($merchant_order, $data, $order); return $this->yesTB($data,'query_coop',$merchant_order); } # 提交接口 一般用于提交数据,异步执行 public function charge(): void { $this->input(); $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->noTB(401003); } $data = $this->channel($this->mid, $this->product, true); // var_dump($data);die; $this->yesTB($data, 'submit', $this->order); } public function charge_test(): void { $this->input(); $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->noTB(401003); } $data = $this->channel($this->mid, $this->product, true); // var_dump($data);die; $this->yesTB($data, 'submit', $this->order); } # 提交接口 一般用于提交数据,异步执行 public function tb_charge() { $this->input_coop(); $settingStatus = sysconf('settingStatus'); if ($settingStatus == 1) { $this->noTB(401003); } $data = $this->channel($this->mid, $this->product, true); $this->yesTB($data, 'submit_coop', $this->order); } # 提交接口 一般用于提交数据,异步执行 public function dc_charge(): void { $this->charge(); } #取消接口 public function cancel() { $data = input(); $tborderfk = array( 'tbOrderNo' => $data['tbOrderNo'], 'coopOrderSuccessTime' => $data['timestamp'], 'coopOrderStatus' => 'GENERAL_ERROR', 'failedReason' => '签名失败', 'failedCode' => '0102', 'coopOrderNo' => "XT".$data['tbOrderNo'] ); $code = 200; $header = [ 'Content-type' =>'text/xml; charset=GBK' ]; return xml($tborderfk,$code,$header,array('root_node' => 'gamezctopcancel', 'encoding' => 'GBK',)); } public function notify($bestUrl,$merchant_order ,$merchant,$apiParams=[]) { $request = $this->getOrder('', $merchant_order); $requestParam = json_decode($request['param'],true); try{ $senddata = $this->doaction($merchant,$request,$requestParam,$apiParams); }catch(Exception $e){ Log::write('errorTip', 'taobao_notify', $e->getMessage()); return 'error'; } $data = (array) $senddata; if(isset($data['update_result']) == 'T'){ return 'success'; }else{ return json_encode($data); } } #授权回调地址 public function gettoken(){ #https://oauth.taobao.com/authorize?response_type=code&client_id=34615444&redirect_uri=http://111.229.70.26/openapi/taobao/gettoken&state=34598038&view=web ##https://oauth.taobao.com/authorize?response_type=code&client_id=34650202&redirect_uri=http://101.43.58.121/openapi/taobao/gettoken&state=34640614&view=web // https://oauth.taobao.com/authorize?response_type=code&client_id=34656002&redirect_uri=http://124.223.48.127/openapi/taobao/gettoken&state=34608230&view=web #http://111.229.70.26/openapi/taobao/gettoken?code=B1iHjrmobM1VDijv4y4AmKSV25209089&state=34598038 $code = input('code'); $agentId = input('state'); $this->agentId = $agentId; $this->getMerchant(); if(isset($this->agentkey)){ $app_data = json_decode($this->merchant['other_param'],true); // $request['agentId'] = '34615444'; // $request['agentkey'] = '2e59a0c00b4fafd9ae46bedced6eccc3'; $request['agentId'] = $app_data['reapi_appkey']; $request['agentkey'] = $app_data['reapi_appsecret']; // $this->mid = '1'; $request['code'] = $code; $token = $this->taobaosdk('getToken',$request); // var_dump($token);die; // print_r($token);die; $token = (array) $token; $token_result = json_decode($token['token_result'],true); $updaterefresh_token = array( 'refresh_token' => $token_result['refresh_token'], 'access_token' => $token_result['access_token'], 'access_token_time' => time() + $token_result['expires_in'] ); // var_dump($updaterefresh_token);die; Db::name('merchant_list')->where('id', $this->mid)->update($updaterefresh_token); } $this->redirect('/'); } /** * @param mixed $merchant_order * @param mixed $data * @param string $order * @return array|mixed */ public function queryData(mixed $merchant_order, mixed $data, string $order): mixed { if (!$this->agentId) { $this->noTB('0101', 'query', $merchant_order); } $this->getMerchant(); //TODO修改 if ($data) { $data = is_array($data) ? $data : json_decode($data, true); } else { $data = $this->getOrder($order, $merchant_order); } if (!$data) { $this->noTB('0104', 'query', $merchant_order); } return $data; } }