176 lines
4.4 KiB
PHP
176 lines
4.4 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\kami\controller\suoka;
|
||
|
|
||
|
|
||
|
use app\kami\controller\getcookie\ZhongZhao as ZhongZhaoCookie;
|
||
|
|
||
|
|
||
|
use dever\Log;
|
||
|
use think\admin\Controller;
|
||
|
|
||
|
#骏卡锁卡-官方api
|
||
|
|
||
|
class JunKa extends Core
|
||
|
{
|
||
|
# 登录获取
|
||
|
public function suoka($cid,$cardno,$cardpwd,$pid,$cash,$num = 0)
|
||
|
{
|
||
|
$param = [];
|
||
|
$param['lock_type'] = 1;
|
||
|
|
||
|
|
||
|
$msg = $this->send($param,$cid,$cardno,$cardpwd,$cash);
|
||
|
|
||
|
if($msg=='ok' || $msg=='old_ok'){
|
||
|
|
||
|
|
||
|
return $msg;
|
||
|
}else{
|
||
|
Log::write('suoka', 'junka', $msg);
|
||
|
return 'error';
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public function send($param,$cid,$cardno,$cardpwd,$cash){
|
||
|
$ChanelInfo = $this->getChanelInfo($cid);
|
||
|
if(!$ChanelInfo == '渠道错误'){
|
||
|
return 'error';
|
||
|
}
|
||
|
$suokaRequest = $this->getChanelSuoKaData($cid);
|
||
|
|
||
|
|
||
|
|
||
|
$url = $suokaRequest['suoka_url'];
|
||
|
$request=$param;
|
||
|
$request['agent_id']=$ChanelInfo['mid'];
|
||
|
$request['account_type']=$suokaRequest['account_type'];
|
||
|
if(isset($suokaRequest['ucard_seller_id']) &&$suokaRequest['ucard_seller_id']){
|
||
|
$request['ucard_seller_id']=$suokaRequest['ucard_seller_id'];
|
||
|
}
|
||
|
|
||
|
$request['card_no']=$cardno;
|
||
|
$request['card_par_amt']=$cash;
|
||
|
$request['card_style']='1';
|
||
|
$request['time_stamp'] =date('YmdHis');
|
||
|
$token = $ChanelInfo['token'];
|
||
|
|
||
|
|
||
|
$request['sign'] = $this->_sign($request, array('agent_id', 'account_type', 'card_no', 'card_par_amt', 'card_style', 'lock_type', 'time_stamp'),$token);
|
||
|
$response = http_get($url,$request);
|
||
|
$response = iconv('GBK', 'UTF-8', $response);
|
||
|
|
||
|
// var_dump($response);die;
|
||
|
// ret_code=***&ret_msg=***&agent_id=***&card_no=***&card_par_amt=***&sign=***
|
||
|
|
||
|
$pairs = explode('&', $response);
|
||
|
|
||
|
// 将每个键值对分割并创建数组
|
||
|
$array = [];
|
||
|
|
||
|
foreach ($pairs as $pair) {
|
||
|
// 分割键和值
|
||
|
list($key, $value) = explode('=', $pair);
|
||
|
// 解码键和值
|
||
|
$array[urldecode($key)] = urldecode($value);
|
||
|
}
|
||
|
// var_dump($array);die;
|
||
|
|
||
|
if (!$array) {
|
||
|
|
||
|
$msg = 'error';
|
||
|
} elseif (isset($array['ret_code']) && $array['ret_code'] == '0' || $array['ret_code'] == '999') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
|
||
|
|
||
|
} elseif(isset($array['ret_msg']) && $array['ret_code'] == '1' && $array['ret_msg'] == '该卡已被锁定') {
|
||
|
$msg = 'old_ok';
|
||
|
|
||
|
}else{
|
||
|
# 错误
|
||
|
$msg = $array['ret_msg'] ?? 'error';
|
||
|
|
||
|
}
|
||
|
|
||
|
return $msg;
|
||
|
|
||
|
}
|
||
|
|
||
|
private function _sign($request, $param,$token)
|
||
|
{
|
||
|
//ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
// if (isset($request[$v]) && $request[$v]) {
|
||
|
|
||
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
||
|
|
||
|
}
|
||
|
|
||
|
$signature_string = substr($signature_string, 0, -1);
|
||
|
|
||
|
$signature_string .= '|||'.$token;
|
||
|
// var_dump($signature_string);die;
|
||
|
// $signature_string = iconv("UTF-8", "gbk", $signature_string);
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
|
||
|
public function chanelsuoka($cid,$cardno,$cardpwd,$pid,$cash,$num = 0)
|
||
|
{
|
||
|
$param = [];
|
||
|
$param['lock_type'] = 2;
|
||
|
|
||
|
|
||
|
$msg = $this->send($param, $cid, $cardno, $cardpwd, $cash);
|
||
|
|
||
|
if ($msg == 'ok') {
|
||
|
|
||
|
|
||
|
return 'ok';
|
||
|
} else {
|
||
|
Log::write('suoka', 'junka', $msg);
|
||
|
return 'error';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function replaceCard($cid,$cardno,$cardpwd,$card_kind,$cash,$order_id,$num = 0)
|
||
|
{
|
||
|
$ChanelInfo = $this->getChanelInfo($cid);
|
||
|
if(!$ChanelInfo == '渠道错误'){
|
||
|
return 'error';
|
||
|
}
|
||
|
$replaceCardRequest = $this->getChanelSuoKaData($cid);
|
||
|
$url = $replaceCardRequest['replace_url'];
|
||
|
$param = [];
|
||
|
$param['agent_id'] = $ChanelInfo['mid'];
|
||
|
$param['version'] = 1;
|
||
|
$param['bill_id'] = $order_id;
|
||
|
$param['bill_time'] = date('YmdHis');
|
||
|
|
||
|
$param['card_kind'] = $card_kind;
|
||
|
$param['card_style'] = 1;
|
||
|
$param['card_price']=$cash;
|
||
|
$param['total_amt']=$cash;
|
||
|
$param['card_data']=$cash;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$msg = $this->send($param, $cid, $cardno, $cardpwd, $cash);
|
||
|
|
||
|
if ($msg == 'ok') {
|
||
|
|
||
|
|
||
|
return 'ok';
|
||
|
} else {
|
||
|
Log::write('suoka', 'junka', $msg);
|
||
|
return 'error';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|