247 lines
6.5 KiB
PHP
247 lines
6.5 KiB
PHP
<?php
|
||
|
||
namespace app\channel\service\system;
|
||
use app\channel\service\KamiService;
|
||
use app\merchant\service\MerchantService;
|
||
use app\merchant\service\OrderService;
|
||
|
||
/**
|
||
* 骏网接口
|
||
* Class Junka
|
||
* @package app\channel\service
|
||
*/
|
||
class Xmfumo extends Core
|
||
{
|
||
# 这几个可以后台设置
|
||
protected $host = '';
|
||
protected $mid = '';
|
||
protected $token = '';
|
||
protected $api = '';
|
||
protected $aeskey = '';
|
||
protected $goodid = '';
|
||
|
||
|
||
public function cardbuy($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'num' => 'num',
|
||
'cash'=>'money',
|
||
|
||
);
|
||
|
||
$this->api = 'buycard';
|
||
return $this->submit($param, $check);
|
||
}
|
||
|
||
|
||
private function submit($param, $check)
|
||
{
|
||
$param = $this->param($param, $check);
|
||
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
return $param;
|
||
}
|
||
|
||
|
||
$request = $param['detail'];
|
||
$request['merchantNo'] = $this->mid;
|
||
$request['orderNo'] = $param['order'];
|
||
|
||
$request['productCode'] = $this->getGid($param['cash']);
|
||
|
||
$request['sign'] = md5($request['productCode'].'&'.$request['money'].'&'.$request['num'].'|'.$this->token);
|
||
$url = $this->host . $this->api;
|
||
|
||
|
||
$response = $this->curl('post', $url, $request);
|
||
$response = $this->response($response);
|
||
|
||
$channel_order_id = '';
|
||
if (isset($response['array']['order_no'])) {
|
||
$channel_order_id = $response['array']['order_no'];
|
||
}
|
||
|
||
if(isset($param['account'])){
|
||
|
||
}elseif(isset($response['kami']['cardno']) ){
|
||
$param['account'] = $response['kami']['cardno'];
|
||
}else{
|
||
$param['account'] = $request['productCode'];
|
||
}
|
||
|
||
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
return $response['msg'];
|
||
}
|
||
|
||
|
||
|
||
# 数据响应格式处理
|
||
|
||
|
||
public function response($data)
|
||
{
|
||
// $data = $this->charsetToUTF8($data);
|
||
$log['type'] = 'response';
|
||
$log['data'] = $data;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
|
||
|
||
#{"code":1,"data":"\u8ba2\u5355\u53f7\uff1a7233874012429511\n\u5361\u53f7\uff1a2312291293609114 \u5bc6\u7801\uff1a0262100598114875 \u8fc7\u671f\u65f6\u95f4\uff1a2027-07-23 00:00:00","order_no":"7233874012429511","msg":"\u8d2d\u4e70\u6210\u529f"}
|
||
|
||
|
||
|
||
$array = $this->json_decode($data);
|
||
|
||
if (!$array) {
|
||
$msg = 'error';
|
||
} elseif (isset($array['code']) && $array['code'] == '1') {
|
||
// var_dump($array);die;
|
||
|
||
|
||
# 正确
|
||
if(isset($array['data'])){
|
||
if(strstr($array['data'], '卡号')){
|
||
$msg = 'yescard';
|
||
|
||
$length1=strpos($array['data'],'密码:')-strpos($array['data'],'卡号:');
|
||
if(strstr($array['data'], '过期时间:')){
|
||
$length2=strpos($array['data'],'过期时间:')-strpos($array['data'],'密码:');
|
||
$keystr=substr($array['data'],strpos($array['data'],'密码:'),$length2);
|
||
}else{
|
||
$keystr=substr($array['data'],strpos($array['data'],'密码:'));
|
||
|
||
}
|
||
|
||
|
||
$cardstr=substr($array['data'],strpos($array['data'],'卡号:'),$length1);
|
||
|
||
// var_dump($keystr);die;
|
||
$time=substr($array['data'],strpos($array['data'],'过期时间:'));
|
||
|
||
$array['kami'] = [];
|
||
$array['kami']['cardno']=trim(explode(':',$cardstr)[1]);
|
||
$array['kami']['cardpwd']=trim(explode(':',$keystr)[1]);
|
||
if(strtotime($time)!==false){
|
||
|
||
$array['kami']['expired']=$time?trim(explode(":",$time)[1]):'';
|
||
}else{
|
||
$array['kami']['expired']='2030-07-24 00:00:00';
|
||
}
|
||
|
||
|
||
}else{
|
||
$msg = 'ok';
|
||
}
|
||
|
||
}else{
|
||
$msg = 'ok';
|
||
}
|
||
|
||
} else {
|
||
# 错误
|
||
$msg = $array['ret_msg'] ?? 'error';
|
||
}
|
||
|
||
|
||
return array
|
||
(
|
||
'msg' => $msg,
|
||
'data' => $array,
|
||
'array' => $array,
|
||
);
|
||
}
|
||
|
||
|
||
#换卡查询接口
|
||
|
||
|
||
|
||
# 锁卡接口
|
||
|
||
public function lockCard($order)
|
||
{
|
||
$request=[];
|
||
$request['merchantNo'] = $this->mid;
|
||
$request['money'] = $order['cash'];
|
||
$response = $this->json_decode($order['response']);
|
||
if(empty($response['kami'])){
|
||
return '未找到卡密';
|
||
}
|
||
$request['cardNo'] = $response['kami']['cardno'];
|
||
$request['type'] = '0';
|
||
$request['time'] =time();
|
||
|
||
|
||
$request['sign'] = md5($request['cardNo'].'&'.$request['money'].'&'.$request['type'].'&'.$request['time'].'|'.$this->token);
|
||
|
||
$url = $this->host . 'lock';
|
||
// var_dump($request);die;
|
||
|
||
|
||
$data = $this->curl('post', $url, $request);
|
||
// print_r($data);die;
|
||
// var_dump($data);
|
||
|
||
$log['type'] = 'LockCard_response';
|
||
$log['data'] = $data;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
|
||
$array = $this->json_decode($data);
|
||
|
||
if (!$array) {
|
||
return 'error';
|
||
} elseif (isset($array['code']) && $array['code'] == '1') {
|
||
|
||
# 正确
|
||
return 'ok';
|
||
|
||
} else {
|
||
# 错误
|
||
return 'error';
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
# 查询接口
|
||
|
||
|
||
|
||
public function query($order)
|
||
{
|
||
|
||
$request['merchantNo'] = $this->mid;
|
||
$request['order_sn'] = $order['channel_order_id'];
|
||
$request['time'] =time();
|
||
|
||
$request['sign'] = md5( $request['order_sn'].'&'.$request['time'].'|'.$this->token );
|
||
$url = $this->host . 'checkorder';
|
||
$response = $this->curl('post', $url, $request);
|
||
|
||
$log['type'] = 'query_response';
|
||
$log['data'] = $response;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
$result= '';
|
||
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
public function upOrderResponse($kami,$merchant_order_id,$orderResponse)
|
||
{
|
||
$orderService = OrderService::instance();
|
||
|
||
$response = json_decode($orderResponse,true);
|
||
$response['kami'] = $kami;
|
||
$data = ['response' => json_encode($response)];
|
||
|
||
$orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data);
|
||
}
|
||
|
||
|
||
} |