REAPI/app/openapi/controller/MiniProgramsApi.php

250 lines
6.4 KiB
PHP
Raw Normal View History

<?php
namespace app\openapi\controller;
use app\core\Service;
use app\gateway\service\RedisService as redisObj;
use app\merchant\service\MerchatMappingProductService;
use think\exception\HttpResponseException;
/**
* 接口处理
* Class Kuaishou
* @package app\gateway\api
*/
class MiniProgramsApi extends Core
{
# 是否检测数据
protected $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 getIsp()
{
$data = input();
if(!isset($data['mobile'])){
$this->no(-100);
}
$isp = Service::instance()->ispguishudi($data['mobile']);
$isp_array = [
'移动'=>1,
'联通'=>2,
'电信'=>3
];
if(is_array($isp)){
$response =$isp;
$response['mobile']=$data['mobile'];
$response['isp'] = $isp_array[$isp['sp']];
$this->yes($response,'ok', 2000);
}
$this->no(-100);
}
public function getProduct()
{
$data = input();
$response = [];
$response[] = [
'isp' => 1,
'name' => '移动',
'product_key' => 'ydcz',
'all_cash' => [
[
'cash' => 100,
'price' => '98.15',
],
[
'cash' => 200,
'price' => '196.30',
],
[
'cash' => 300,
'price' => '294.45',
],
[
'cash' => 500,
'price' => '492.60',
],
[
'cash' => 50,
'price' => '50.20',
],
]
];
$response[] = [
'isp' => 2,
'name' => '联通',
'product_key' => 'ltcz',
'all_cash' => [
[
'cash' => 100,
'price' => '98.15',
],
[
'cash' => 200,
'price' => '196.30',
],
[
'cash' => 300,
'price' => '294.45',
]
]
];
$response[] = [
'isp' => 3,
'name' => '电信',
'product_key' => 'dxcz',
'all_cash' => [
[
'cash' => 100,
'price' => '98.15',
],
[
'cash' => 200,
'price' => '196.30',
],
[
'cash' => 300,
'price' => '294.45',
]
]
];
$this->yes($response,'ok', 2000);
}
# 提交接口 一般用于提交数据,异步执行
public function charge()
{
}
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);
}
}