167 lines
4.5 KiB
PHP
167 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace app\openapi\controller;
|
|
|
|
use app\channel\service\ChannelService;
|
|
use app\channel\service\ProductService;
|
|
use app\gateway\service\RedisService as redisObj;
|
|
use app\merchant\service\MerchatMappingProductService;
|
|
use app\merchant\service\OrderHistoryService;
|
|
use app\merchant\service\OrderService;
|
|
use app\merchant\service\ProductService as MerchantProductService;
|
|
use think\exception\HttpResponseException;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 接口处理
|
|
* 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()
|
|
{
|
|
|
|
$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 test_charge(){
|
|
$this->input_test();
|
|
|
|
|
|
|
|
$settingStatus = sysconf('settingStatus');
|
|
if ($settingStatus == 1) {
|
|
$this->noKS(401003);
|
|
}
|
|
|
|
|
|
|
|
$data = $this->channel($this->mid, $this->product);
|
|
// $data = $this->channel($this->mid, $this->product);
|
|
var_dump($data);
|
|
|
|
// $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'];
|
|
// var_dump($code);
|
|
#https://open.kuaishou.com/oauth2/authorize?app_id=ks711568745145555943&redirect_uri=https%3A%2F%2Fcz.njxshy.com%2Fopenapi%2Fkuaishou%2Fopencode&scope=merchant_shop,merchant_funds,merchant_item,merchant_order,merchant_promotion,merchant_user,merchant_refund,user_info,merchant_video,merchant_material,merchant_comment,merchant_logistics&response_type=code
|
|
|
|
$url = 'https://openapi.kwaixiaodian.com/oauth2/access_token';
|
|
|
|
|
|
$appid = 'ks711568745145555943';
|
|
$grant_type = 'code';
|
|
$app_secret = 'acvkSeobHEijweCAwhJ5Zw';
|
|
$url = $url.'?app_id='.$appid.'&grant_type='.$grant_type.'&code='.$code.'&app_secret='.$app_secret;
|
|
// var_dump($url);die;
|
|
|
|
// $response = $this->send_get($url);
|
|
$response = http_get($url);
|
|
// print_r($response);die;
|
|
// var_dump($response);die;
|
|
|
|
$responseData = json_decode($response,true);
|
|
|
|
$merchant = \app\merchant\service\MerchantService::instance();
|
|
#注意修改
|
|
$mid = '4';
|
|
$update = array(
|
|
'refresh_token' =>$responseData['refresh_token']
|
|
);
|
|
|
|
|
|
$merchant->db()->where(array('id' => $mid))->update($update);
|
|
|
|
|
|
}
|
|
|
|
|
|
} |