2024-09-29 15:43:18 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\openapi\controller;
|
|
|
|
|
|
|
|
|
|
use app\gateway\service\CurlService;
|
|
|
|
|
use app\gateway\service\RedisService as redisObj;
|
|
|
|
|
use app\merchant\service\MerchantService;
|
|
|
|
|
use app\merchant\service\OrderHistoryService;
|
|
|
|
|
use app\merchant\service\OrderService;
|
|
|
|
|
use app\order\service\Kami91OrderService;
|
|
|
|
|
use think\admin\Controller;
|
|
|
|
|
use app\core\Service as CoreService;
|
|
|
|
|
use think\facade\Log;
|
|
|
|
|
|
|
|
|
|
class Kami91 extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
# <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// protected bool $check = false;
|
|
|
|
|
protected $merchant_id;
|
|
|
|
|
|
|
|
|
|
# code<64>붨<EFBFBD><EBB6A8>
|
2025-06-03 18:55:03 +08:00
|
|
|
|
|
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
protected $code = array
|
|
|
|
|
(
|
|
|
|
|
# <20>ɹ<EFBFBD>
|
|
|
|
|
1 => 'ok',
|
|
|
|
|
# С<><D0A1>0Ϊʧ<CEAA><CAA7>
|
|
|
|
|
-1 => 'appidΪ<64><CEAA>',
|
|
|
|
|
-2 => '<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>',
|
|
|
|
|
-3 => 'appid<69><64>Ч',
|
|
|
|
|
-4 => '<27><><EFBFBD><EFBFBD><EEB2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>۸<EFBFBD>',
|
|
|
|
|
|
|
|
|
|
-5 => 'signature<72><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>',
|
|
|
|
|
-6 => 'nonce<63><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>',
|
|
|
|
|
-7 => 'time<6D><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>',
|
|
|
|
|
-8 => 'signature<72><65>ʧЧ',
|
|
|
|
|
-9 => 'signature<72><65>֤ʧ<D6A4><CAA7>',
|
|
|
|
|
|
|
|
|
|
-100 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
|
|
|
|
-101 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
|
|
|
|
-102 => '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>',
|
|
|
|
|
|
|
|
|
|
-103 => '<27><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>',
|
|
|
|
|
|
|
|
|
|
-1000 => 'ϵͳά<CDB3><CEAC><EFBFBD><EFBFBD>',
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
# <20><>ѯ<EFBFBD>ӿ<EFBFBD> һ<><D2BB><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD>ݣ<EFBFBD>ͬ<EFBFBD><CDAC>ִ<EFBFBD><D6B4>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# <20>ύ<EFBFBD>ӿ<EFBFBD> һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ύ<EFBFBD><E1BDBB><EFBFBD>ݣ<EFBFBD><DDA3>첽ִ<ECB2BD><D6B4>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function query()
|
|
|
|
|
{
|
|
|
|
|
$data = input();
|
|
|
|
|
if(empty($data['api_product']) || $data['api_product'] != 'query'){
|
|
|
|
|
$this->no(-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($data['appid'])) {
|
|
|
|
|
$this->no(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($data['merchant_order_id'])) {
|
|
|
|
|
$this->no(-100);
|
|
|
|
|
}
|
|
|
|
|
// http_post($url, $data)
|
|
|
|
|
|
|
|
|
|
$getMerchantInfo = MerchantService::instance()->get($data['appid']);
|
|
|
|
|
// $mid = $getMerchantInfo['id'];
|
|
|
|
|
$info = Kami91OrderService::instance()->db()->where(['merchant_order_id' => $data['merchant_order_id']])->find();
|
|
|
|
|
if(!$info){
|
|
|
|
|
$this->no(-100);
|
|
|
|
|
}
|
|
|
|
|
$order = $this->getOrder('', $data['merchant_order_id'] ,$getMerchantInfo['id']);
|
|
|
|
|
|
|
|
|
|
if(!$order){
|
|
|
|
|
$this->no(-101);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($order['status'] == 2){
|
|
|
|
|
if(empty($info['cardno'])){
|
|
|
|
|
$data = ['msg' => '<27><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>'];
|
|
|
|
|
$this -> no(-103);
|
|
|
|
|
}
|
|
|
|
|
$data = [
|
|
|
|
|
'CardNum' => $info['cardno'],
|
|
|
|
|
'CardPassword' => $info['cardpwd'],
|
|
|
|
|
'expireDate' => $info['expire_time']
|
|
|
|
|
];
|
|
|
|
|
}elseif ($order['status'] == 7){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($info['status'] == '1'){
|
|
|
|
|
$data =array();
|
|
|
|
|
$data['order_id'] = $order['order_id'];
|
|
|
|
|
$data['status'] = 4;
|
|
|
|
|
Kami91OrderService::instance()->db()->where(array('merchant_order_id' => $order['merchant_order_id']))->update($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->huidiao($order['order_id']);
|
|
|
|
|
|
|
|
|
|
if(empty($info['cardno'])){
|
|
|
|
|
$response = json_decode($order['response'],true);
|
|
|
|
|
//
|
|
|
|
|
if(isset($response['kami'])) {
|
|
|
|
|
|
|
|
|
|
$cardno = $response['kami']['cardno'];
|
|
|
|
|
$cardpwd = $response['kami']['cardpwd'];
|
|
|
|
|
$expire_time= $response['kami']['expired'];
|
|
|
|
|
}else{
|
|
|
|
|
$this->no(-103);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$cardno = $info['cardno'];
|
|
|
|
|
$cardpwd = $info['cardpwd'];
|
|
|
|
|
$expire_time= $info['expire_time'];
|
|
|
|
|
}
|
|
|
|
|
$data = [
|
|
|
|
|
'CardNum' => $cardno,
|
|
|
|
|
'CardPassword' => $cardpwd,
|
|
|
|
|
'expireDate' => $expire_time
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
$this->no(-100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this->yes($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getOrder($order_id, $merchant_order_id = false ,$mid = false)
|
|
|
|
|
{
|
|
|
|
|
$orderService = OrderService::instance();
|
|
|
|
|
$order = $orderService->get($order_id, $merchant_order_id ,$mid);
|
|
|
|
|
if (!$order) {
|
|
|
|
|
$orderHistoryService = OrderHistoryService::instance();
|
|
|
|
|
$order = $orderHistoryService->get($order_id, $merchant_order_id ,$mid);
|
|
|
|
|
}
|
|
|
|
|
return $order;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
|
{
|
|
|
|
|
#ע<><D7A2><EFBFBD><EFBFBD>id
|
|
|
|
|
// $this->mid = '2';
|
|
|
|
|
|
|
|
|
|
$input = input();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
|
|
|
|
|
if (!$input) {
|
|
|
|
|
$this->no(-100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$input['appid']) {
|
|
|
|
|
$this->no(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$input['order']) {
|
|
|
|
|
$this->no(-100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$order = '';
|
|
|
|
|
$merchant_order = $input['order'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($input['proid'])) {
|
|
|
|
|
# <20><><EFBFBD>ݲ<EFBFBD>Ʒid <20><>ȡ<EFBFBD><C8A1>Ϣ
|
|
|
|
|
$pinfo = \app\channel\service\ProductBaseService::instance()->getOne($input['proid']);
|
|
|
|
|
if (!$pinfo) {
|
|
|
|
|
$this->no(-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data['product_key'] = $pinfo['key'];
|
|
|
|
|
$data['cash'] = $pinfo['value'] ;
|
|
|
|
|
$pid = \app\channel\service\ProductBaseService::instance()->getProductId($pinfo['service_id']);
|
|
|
|
|
|
|
|
|
|
$data['pid'] = $pid['id'];
|
|
|
|
|
} else {
|
|
|
|
|
$this->no(-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data['status'] = '1';
|
|
|
|
|
$data['param'] = json_encode($input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if ($data['request'] && $data['status'] == '-7') {
|
|
|
|
|
// $data['request'] = json_decode($data['request'], true);
|
|
|
|
|
//// \app\gateway\controller\api\Task::run($data['request'], true);
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
$getMerchantInfo = MerchantService::instance()->get($input['appid']);
|
|
|
|
|
$data['mid'] = $getMerchantInfo['id'];
|
|
|
|
|
$orderdata = $this->getOrder($order, $merchant_order ,$getMerchantInfo['id']);
|
|
|
|
|
|
|
|
|
|
if(!$orderdata){
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
$data['status'] = '4';
|
|
|
|
|
$data['order_id'] = $orderdata['order_id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$where = [
|
|
|
|
|
'mid' => $data['mid'],
|
|
|
|
|
'merchant_order_id' => $merchant_order
|
|
|
|
|
];
|
|
|
|
|
$data['merchant_order_id'] = $merchant_order;
|
|
|
|
|
$data['notifyurl'] = $input['notify'];
|
|
|
|
|
|
|
|
|
|
$result = Kami91OrderService::instance()->up($where,$data);
|
|
|
|
|
|
|
|
|
|
if(!is_numeric($result)){
|
|
|
|
|
$this->no(-1000);
|
|
|
|
|
}
|
|
|
|
|
// var_dump($orderdata);die;
|
|
|
|
|
|
|
|
|
|
if(isset($orderdata['status']) && $orderdata['status'] == '7'){
|
|
|
|
|
$this->huidiao($orderdata['order_id']);
|
|
|
|
|
}
|
|
|
|
|
$this->yes('ok');
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function huidiao($order_id)
|
|
|
|
|
{
|
|
|
|
|
// var_dump(123);die;
|
|
|
|
|
$order = $this->getOrder($order_id);
|
|
|
|
|
|
|
|
|
|
if(isset($order['channel_callback_msg'])){
|
|
|
|
|
|
|
|
|
|
$msg = json_decode($order['channel_callback_msg'],true);
|
|
|
|
|
if(isset($msg['kami'])){
|
|
|
|
|
OrderService::instance()->upStatus($order_id);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
$response = json_decode($order['response'],true);
|
|
|
|
|
//
|
|
|
|
|
if(isset($response['kami'])){
|
|
|
|
|
// var_dump($response['kami']);die;
|
|
|
|
|
$kami = [
|
|
|
|
|
'cardno' =>$response['kami']['cardno'],
|
|
|
|
|
'cardpwd' =>$response['kami']['cardpwd'],
|
|
|
|
|
'expire_time' =>$response['kami']['expired'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$where = [
|
|
|
|
|
'order_id' => $order_id
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$result = Kami91OrderService::instance()->up($where,$kami);
|
|
|
|
|
OrderService::instance()->upChannelMsg($order_id,'2',['kami' => $response['kami'],'s_nubmer'=>$response['kami']['cardno']]);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
return 'error';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $order['merchant_callback_error'] != 1) {
|
|
|
|
|
// var_dump(123);die;
|
|
|
|
|
//$update['order'] = $order;
|
|
|
|
|
$update = [];
|
|
|
|
|
$update['status'] = $order['status'];
|
|
|
|
|
|
|
|
|
|
$update['account'] = $order['account'];
|
|
|
|
|
$update['cash'] = $order['cash'];
|
|
|
|
|
$update['merchant_order_id'] = $order['merchant_order_id'];
|
|
|
|
|
$update['order_id'] = $order_id;
|
|
|
|
|
$update['notify_num'] = $order['merchant_callback_num'];
|
|
|
|
|
$order['param'] = json_decode($order['param'],true);
|
|
|
|
|
|
|
|
|
|
if ($order['param'] && isset($order['param']['notify']) && $order['param']['notify']) {
|
|
|
|
|
$update['notify'] = $order['param']['notify'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# <20>̻<EFBFBD><CCBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
if (isset($order['error_account_oper']) && $order['error_account_oper'] == 1) {
|
|
|
|
|
# <20><>Ҫ<EFBFBD><D2AA><EFBFBD>п۷<D0BF>
|
|
|
|
|
MerchantService::instance()->up($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
|
|
|
|
} else {
|
|
|
|
|
# ֱ<>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
MerchantService::instance()->notify($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return 'ok';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# <20>ύ<EFBFBD>ӿ<EFBFBD> һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ύ<EFBFBD><E1BDBB><EFBFBD>ݣ<EFBFBD><DDA3>첽ִ<ECB2BD><D6B4>
|
|
|
|
|
public function dc_charge(): void
|
|
|
|
|
{
|
|
|
|
|
$this->submit();
|
|
|
|
|
}
|
|
|
|
|
// protected function getMerchant(): void
|
|
|
|
|
// {
|
|
|
|
|
// $this->merchant = MerchantService::instance()->get('PT_'.$this->agentId);
|
|
|
|
|
// $this->mid = $this->merchant['id'];
|
|
|
|
|
//
|
|
|
|
|
//// $this->agentId = $this->merchant['agentId'];
|
|
|
|
|
//
|
|
|
|
|
// $this->agentkey = $this->merchant['agentkey'];
|
|
|
|
|
//
|
|
|
|
|
// $this->callnotify = $this->merchant['notify_url'];
|
|
|
|
|
//// $this->signkey = $this->merchant['other_key'];
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function curl($method, $url, $param = array(), $json = false, $header = false):mixed
|
|
|
|
|
{
|
|
|
|
|
if ($param) {
|
|
|
|
|
$log['type'] = 'request';
|
|
|
|
|
$log['url'] = $url;
|
|
|
|
|
$log['param'] = $param;
|
|
|
|
|
$this->log($log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$curl = CurlService::getInstance($url, $param, $method, $json, $header);
|
|
|
|
|
$curl->setTimeOut(3600);
|
|
|
|
|
return $curl->result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function log($data, $type = 'request'):void
|
|
|
|
|
{
|
|
|
|
|
\dever\Log::write('kami91', $type, $data);
|
|
|
|
|
// \dever\Log::write('jingdong', $type, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function kaminotify( $order_id ,$status)
|
|
|
|
|
{
|
|
|
|
|
$kami91Service = Kami91OrderService::instance();
|
|
|
|
|
$getkami91info = $kami91Service->getOrder(1, $order_id);
|
|
|
|
|
$url = $getkami91info['notifyurl'];
|
|
|
|
|
$param = array();
|
|
|
|
|
$param['status'] = $status;
|
|
|
|
|
if ($status == 2){
|
|
|
|
|
$param['cardno'] = $getkami91info['cardno'];
|
|
|
|
|
$param['cardpwd'] = $getkami91info['cardpwd'];
|
|
|
|
|
$param['expire_time'] = $getkami91info['expire_time'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$header['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
|
// var_dump($param);die;
|
|
|
|
|
// $msg = http_post( $url, $param);
|
|
|
|
|
|
|
|
|
|
// $msg = $this->send_post( $url, $param, 'POST');
|
|
|
|
|
$msg = 'success';
|
|
|
|
|
// var_dump($msg);die;
|
|
|
|
|
$this->log($msg,'msg');#д<>뵽<EFBFBD><EBB5BD>־<EFBFBD><D6BE>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($msg != 'success'){
|
|
|
|
|
$this->log($msg,'errormsg');#д<>뵽<EFBFBD><EBB5BD>־<EFBFBD><D6BE>
|
|
|
|
|
$callbalck_status = '3';
|
|
|
|
|
}else{
|
|
|
|
|
$callbalck_status = '2';
|
|
|
|
|
}
|
|
|
|
|
$upstatus = $kami91Service->upStatus($order_id, $callbalck_status ,$msg);
|
|
|
|
|
|
|
|
|
|
if ($callbalck_status == 3){
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $upstatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function send_post($notify_url, $post_data, $type): mixed
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$postdate = http_build_query($post_data);
|
|
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
'http' => array(
|
|
|
|
|
'method' => $type,
|
|
|
|
|
'header' => 'Content-type:application/x-www-form-urlencoded',
|
|
|
|
|
'content' => $postdate,
|
|
|
|
|
'timeout' => 15 * 60 // <20><>ʱʱ<CAB1>䣨<EFBFBD><E4A3A8>λ:s<><73>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$context = stream_context_create($options);
|
|
|
|
|
return file_get_contents($notify_url, false, $context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param mixed $info
|
|
|
|
|
* @param string $data
|
|
|
|
|
* @param integer $code
|
|
|
|
|
*/
|
|
|
|
|
protected function no($code = 0, $info = '', $data = '{-null-}')
|
|
|
|
|
{
|
|
|
|
|
$msg = $this->code[$code] ?? 'error';
|
|
|
|
|
if ($info) {
|
|
|
|
|
$msg .= ':' . $info;
|
|
|
|
|
}
|
|
|
|
|
$data = '{-null-}';
|
|
|
|
|
$this->error($msg, $data, $code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>سɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param mixed $info
|
|
|
|
|
* @param string $data
|
|
|
|
|
* @param integer $code
|
|
|
|
|
*/
|
|
|
|
|
protected function yes($data = '{-null-}', $info = 'ok', $code = 1)
|
|
|
|
|
{
|
|
|
|
|
if (is_string($data) && $data != 'ok' && $data != 'success') {
|
|
|
|
|
if ($data == '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>') {
|
|
|
|
|
return $this->no(-102);
|
|
|
|
|
}
|
|
|
|
|
return $this->no(-100, $data);
|
|
|
|
|
}
|
|
|
|
|
$this->success($info, $data, $code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|