REAPI/app/gateway/controller/api/Kuaishou.php

137 lines
3.4 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\gateway\controller\api;
use app\channel\service\CardService;
use think\exception\HttpResponseException;
use app\gateway\service\RedisService as redisObj;
/**
* 接口处理
* Class Kuaishou
* @package app\gateway\api
*/
class Kuaishou extends Coreks
{
# 是否检测数据
protected bool $check = false;
# 查询接口 一般用于查询数据,同步执行
public function query()
{
$data = input();
$order = '';
$query_param = json_decode($data['param'],true);
$merchant_order = $query_param['orderId'];
$redis=new redisObj();
$data= $redis->get('kuaishou_query'.$merchant_order);
if($data){
$data=is_array($data)?$data:json_decode($data,true);
}else{
$data = $this->getOrder($order, $merchant_order);
}
if (!$data) {
$ksorderfk = array(
'result' => '4012002',
'error_msg' => '订单不存在'
);
throw new HttpResponseException(json($ksorderfk));
}
$date_str = $data['create_at'];
$date_time = new \DateTime($date_str, new \DateTimeZone('Asia/Shanghai'));
$iso8601_date = $date_time->format('Y-m-d\TH:i:s\Z');
$result = array(
'result' => '1',
'error_msg' => ''
);
$result['data'] = array(
"bizType" => '20',
'createTime' =>$iso8601_date,
'mobile' => $data['account'],
'orderId' => $merchant_order,
);
if ($data['status'] == '2') {
$result['data']['status'] = 'SUCCESS';
} elseif ($data['status'] == '3') {
$result['data']['status'] = 'FAILED';
$result['data']['failCode'] = '4013024';
$result['data']['failMsg'] = '上游通道充值失败';
} else {
$result['data']['status'] = 'ACCEPTED';
}
throw new HttpResponseException(json($result));
}
# 提交接口 一般用于提交数据,异步执行
public function charge()
{
#注意修改id
// $this->mid = '2';
$this->input();
$settingStatus = sysconf('settingStatus');
if ($settingStatus == 1) {
$this->noKS(401003);
}
$data = $this->channel($this->mid, $this->product, true);
$this->yesks($data,'submit',$this->order);
}
# 提交接口 一般用于提交数据,异步执行
public function dc_charge(): void
{
$this->charge();
}
#code获取
public function opencode(): void
{
$codedata =$this->request->get();
$code = $codedata['code'];
$url = 'https://openapi.kwaixiaodian.com/oauth2/access_token';
$appid = 'ks700591219246529660';
$grant_type = 'code';
$app_secret = 'USMLVa0BKM7e_j39zBUvfQ';
$url = $url.'?app_id='.$appid.'&grant_type='.$grant_type.'&code='.$code.'&app_secret='.$app_secret;
$response = http_get($url);
// $response = $this->send_get($url);
$responseData = json_decode($response,true);
$merchant = \app\merchant\service\MerchantService::instance();
#注意修改
$mid = '2';
$update = array(
'refresh_token' =>$responseData['refresh_token']
);
$merchant->db()->where(array('id' => $mid))->update($update);
}
}