247 lines
7.2 KiB
PHP
247 lines
7.2 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\openapi\controller;
|
||
|
|
||
|
|
||
|
//require(__DIR__ . "/../../../extend/sdk/taobao/UpdateOrders.php");
|
||
|
|
||
|
//use extend\sdk\taobao\UpdateOrders;
|
||
|
use app\gateway\service\RedisService as redisObj;
|
||
|
use dever\Log;
|
||
|
//use extend\sdk\taobao\GetAccessToken;
|
||
|
use think\facade\Db;
|
||
|
class Taobao_coop extends Coretb
|
||
|
{
|
||
|
|
||
|
# 是否检测数据
|
||
|
protected bool $check = false;
|
||
|
|
||
|
# 查询接口 一般用于查询数据,同步执行
|
||
|
|
||
|
|
||
|
public function query()
|
||
|
{
|
||
|
$data = input();
|
||
|
$data = $this->charsetToUTF8($data);
|
||
|
$order = '';
|
||
|
$merchant_order = $data['tbOrderNo'];
|
||
|
$redis = new redisObj();
|
||
|
$data = $redis->get('taobao_query' . $merchant_order);
|
||
|
// $this->agentId= input('app_key');
|
||
|
$this->agentId= input('supplierId');
|
||
|
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);
|
||
|
}
|
||
|
// $result['coopOrderNo'] = $merchant_order;
|
||
|
//
|
||
|
//
|
||
|
// if ($data['status'] == '2') {
|
||
|
// $result['coopOrderStatus'] = 'SUCCESS';
|
||
|
// $result['coopOrderSnap'] = json_decode($data['param'], true)['tbOrderSnap'];
|
||
|
// $result['coopOrderSuccessTime'] = $data['channel_callback_at'];
|
||
|
// } elseif ($data['status'] == '3') {
|
||
|
// $result['coopOrderStatus'] = 'FAILED';//tbOrderSnap
|
||
|
// $result['failedReason'] = iconv("UTF-8", "gbk", '充值失败');
|
||
|
// $result['failedCode'] = '0503';
|
||
|
//
|
||
|
// } else {
|
||
|
// $result['coopOrderStatus'] = 'UNDERWAY';
|
||
|
// }
|
||
|
|
||
|
|
||
|
return $this->yesTB($data,'query',$merchant_order);
|
||
|
}
|
||
|
|
||
|
public function test1()
|
||
|
{
|
||
|
|
||
|
// $this->input = input();
|
||
|
|
||
|
$this->input();
|
||
|
|
||
|
// $this->input = $this->charsetToUTF8($this->input);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// print_r(json_encode($this->input)); die;
|
||
|
|
||
|
|
||
|
|
||
|
// $this->input = $this->charsetToUTF8($this->input);
|
||
|
// var_dump($this->input);die;
|
||
|
|
||
|
|
||
|
$settingStatus = sysconf('settingStatus');
|
||
|
if ($settingStatus == 1) {
|
||
|
$this->noTB(401003);
|
||
|
}
|
||
|
|
||
|
// $data = $this->channel($this->mid, $this->product, true);
|
||
|
$data = $this->channel($this->mid, $this->product);
|
||
|
var_dump($data);die;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
# 提交接口 一般用于提交数据,异步执行
|
||
|
public function charge()
|
||
|
{
|
||
|
var_dump(111);die;
|
||
|
#注意修改id
|
||
|
// $this->mid = '2';
|
||
|
$this->input_coop();
|
||
|
$settingStatus = sysconf('settingStatus');
|
||
|
if ($settingStatus == 1) {
|
||
|
$this->noTB(401003);
|
||
|
}
|
||
|
// $data = $this->channel($this->mid, $this->product, true);
|
||
|
$data = $this->channel($this->mid, $this->product);
|
||
|
|
||
|
// var_dump($data);die;
|
||
|
// $data
|
||
|
// return $data;
|
||
|
// $data = $this->channel($this->mid, $this->product);
|
||
|
// print_r($data);die;
|
||
|
// var_dump($expression);
|
||
|
|
||
|
$this->yesTB($data, 'submit', $this->order);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
# 提交接口 一般用于提交数据,异步执行
|
||
|
public function dc_charge(): void
|
||
|
{
|
||
|
$this->charge();
|
||
|
}
|
||
|
#取消接口
|
||
|
public function cancel()
|
||
|
{
|
||
|
#注意修改id
|
||
|
// $this->mid = '2';
|
||
|
|
||
|
$data = input();
|
||
|
|
||
|
// $tborderfk = array(
|
||
|
// 'tbOrderNo' => $data['tbOrderNo'],
|
||
|
//// 'coopOrderSuccessTime' => $data['timestamp'],
|
||
|
// 'coopOrderStatus' => 'GENERAL_ERROR',
|
||
|
// 'failedReason' => 'CANCEL',
|
||
|
//// 'failedCode' => '0102',
|
||
|
// 'coopOrderNo' => "XT".$data['tbOrderNo']
|
||
|
// );
|
||
|
$tborderfk = array(
|
||
|
'tbOrderNo' => $data['tbOrderNo'],
|
||
|
'coopOrderSuccessTime' => $data['timestamp'],
|
||
|
'coopOrderStatus' => 'GENERAL_ERROR',
|
||
|
'failedReason' => '签名失败',
|
||
|
'failedCode' => '0102',
|
||
|
'coopOrderNo' => "XT".$data['tbOrderNo']
|
||
|
);
|
||
|
|
||
|
// header("Content-type: text/xml; charset=GBK");
|
||
|
// throw new HttpResponseException(xml($tborderfk));
|
||
|
$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=[])
|
||
|
{
|
||
|
// \UpdateOrder::class
|
||
|
// \extend\sdk\taobao\top\UpdateOrder
|
||
|
$request = $this->getOrder('', $merchant_order);
|
||
|
$requestParam = json_decode($request['param'],true);
|
||
|
|
||
|
try{
|
||
|
// $orderobj=new \UpdateOrders;
|
||
|
// $senddata =$orderobj->doaction($merchant,$request,$requestParam,$apiParams);
|
||
|
|
||
|
$senddata = $this->doaction($merchant,$request,$requestParam,$apiParams);
|
||
|
|
||
|
// $senddata = UpdateOrders::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('/');
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|