312 lines
8.6 KiB
PHP
312 lines
8.6 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();
|
|
|
|
|
|
$settingStatus = sysconf('settingStatus');
|
|
if ($settingStatus == 1) {
|
|
$this->noKS(401003);
|
|
}
|
|
|
|
// var_dump($this->input);die;
|
|
|
|
$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 charge_test()
|
|
{
|
|
|
|
#extend/logs/openapi/08/02kuaishou_request.log
|
|
// $log_data=file_get_contents('extend/logs/openapi/08/02kuaishou_request.log');
|
|
//// $log_data=explode("\n",$log_data);
|
|
//// var_dump($log_data);die;
|
|
///
|
|
// $this->input();
|
|
$is_left=true;
|
|
while($is_left){
|
|
$data = Db::name('kuaishou_request')->limit(1000)->select();
|
|
if($data){
|
|
foreach ($data as $k => $v) {
|
|
$json = ltrim($v['json']);
|
|
$array = json_decode($json,true);
|
|
$this->input = $array;
|
|
$this->agentId = $array['appkey'];
|
|
|
|
if (!$this->agentId) {
|
|
$this->noKS(4013001);
|
|
}
|
|
|
|
|
|
|
|
$this->input = $inputData = $this->input['param'];
|
|
|
|
$order_info = OrderService::instance()->get(false, $this->input['orderId'], $this->mid);
|
|
if (!$order_info) {
|
|
$order_info = OrderHistoryService::instance()->get(false, $this->input['orderId'], $this->mid);
|
|
}
|
|
|
|
if ($order_info) {
|
|
Db::name('kuaishou_request')->whereLike('json', '%'.$this->input['orderId'].'%')->delete();
|
|
// die;
|
|
continue;
|
|
|
|
}
|
|
|
|
if($inputData['bizType'] == '10'){
|
|
$this->agentId = $this->agentId.'_KC';
|
|
}
|
|
if (isset($this->input['test'])) {
|
|
$this->testtrue = 1;
|
|
} else {
|
|
$this->testtrue = 2;
|
|
}
|
|
|
|
if (!$this->input) {
|
|
$this->noKS(4013008);
|
|
}
|
|
|
|
|
|
$this->mappingid = $inputData['relItemId'];
|
|
// $this->product = 'dhcz';
|
|
if ($this->mappingid) {
|
|
# 根据产品id 获取信息
|
|
$pinfo = MerchatMappingProductService::instance()->getOne($this->mappingid);
|
|
$this->pinfo = $pinfo;
|
|
// if($pinfo)
|
|
if (!$pinfo) {
|
|
$this->product = 'dhcz';
|
|
}else {
|
|
|
|
$this->product = $pinfo['key'];
|
|
}
|
|
|
|
} else {
|
|
$this->product = 'dhcz';
|
|
}
|
|
|
|
|
|
|
|
// $this->product = 'dhcz';
|
|
|
|
$this->order = $inputData['orderId'];
|
|
$this->ksorder = $inputData['ksOrderId'];
|
|
|
|
|
|
$this->salePrice = $inputData['price'];
|
|
$this->cash = $inputData['amount'] / 100;
|
|
|
|
|
|
|
|
$this->input['cash'] = $this->cash;
|
|
$this->input['order'] = $this->order;
|
|
$this->encryptAccount = $inputData['encryptAccount'];
|
|
$this->input['getMobile_num'] = 0;
|
|
|
|
unset($this->input['orderId']);
|
|
|
|
|
|
|
|
# 从数据库中或者缓存中取出商户的信息,并验证是否有效
|
|
$this->getMerchant();
|
|
|
|
$this->card = $this->getMobile();
|
|
|
|
|
|
$this->input['card'] = $this->card;
|
|
$this->input['mobile'] = $this->input['card'];
|
|
if (isset($this->input['ksOrderId'])) {
|
|
$this->input['parent_order_id'] = $this->input['ksOrderId'];
|
|
}
|
|
|
|
|
|
$datas = $this->channel($this->mid, $this->product,true);
|
|
|
|
|
|
|
|
var_dump($datas);
|
|
|
|
}
|
|
die;
|
|
|
|
}else{
|
|
$is_left=false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// $pinfo = MerchatMappingProductService::instance()->getOne($this->mappingid);
|
|
var_dump($this->product);
|
|
|
|
return ChannelService::instance()->usetest($this->mid, $this->product, $this->input, true, '');
|
|
var_dump($product_info);die;
|
|
|
|
|
|
$settingStatus = sysconf('settingStatus');
|
|
if ($settingStatus == 1) {
|
|
$this->noKS(401003);
|
|
}
|
|
|
|
// var_dump($this->input);die;
|
|
|
|
// $test = MerchantProductService::instance()->getAll($this->merchant, 'dhcz');
|
|
// var_dump($test);die;
|
|
|
|
$data = $this->channel($this->mid, $this->product);
|
|
|
|
// $data = $this->channel($this->mid, $this->product);
|
|
|
|
$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 = '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 = '1';
|
|
$update = array(
|
|
'refresh_token' =>$responseData['refresh_token']
|
|
);
|
|
|
|
|
|
$merchant->db()->where(array('id' => $mid))->update($update);
|
|
|
|
|
|
}
|
|
|
|
|
|
} |