292 lines
8.4 KiB
PHP
292 lines
8.4 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
use app\channel\service\CardService;
|
||
|
use app\merchant\service\OrderService;
|
||
|
/**
|
||
|
*
|
||
|
* Class Tiancheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Tchong extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = '';
|
||
|
protected $mid = '';
|
||
|
protected $token = '';
|
||
|
protected $card = array();
|
||
|
protected $order_id = '';
|
||
|
protected $api = '';
|
||
|
protected $sign = array();
|
||
|
protected $lprefix = '';
|
||
|
|
||
|
# 系统代充
|
||
|
// public function xtdc($param)
|
||
|
// {
|
||
|
// $check = array
|
||
|
// (
|
||
|
// 'card' => 'number',
|
||
|
// 'cash' => 'money',
|
||
|
// 'cnum' => 'cardNum',
|
||
|
// 'cpwd' => 'cardPwd',
|
||
|
// );
|
||
|
// if (!isset($param['cnum'])) {
|
||
|
// $data = CardService::instance()->getData($param['cash'], $this->data['merchant']);
|
||
|
// if ($data) {
|
||
|
// $this->data['param']['cnum'] = $param['cnum'] = $data['cnum'];
|
||
|
// $this->data['param']['cpwd'] = $param['cpwd'] = $data['cpwd'];
|
||
|
//
|
||
|
// $this->card = $data;
|
||
|
// $this->card_id = $this->card['id'];
|
||
|
// } else {
|
||
|
// $this->card_id = -1;
|
||
|
// }
|
||
|
// }
|
||
|
// $this->sign = array('username', 'orderNumber', 'number', 'cardNum', 'cardPwd', 'productNo', 'money', 'orderTime', 'privateKey');
|
||
|
// $this->api = 'api/v2/submitOrder';
|
||
|
// return $this->submit($param, $check);
|
||
|
// }
|
||
|
|
||
|
# 电话充值
|
||
|
// public function common($param)
|
||
|
// {
|
||
|
// $check = array
|
||
|
// (
|
||
|
// 'account' => 'number',
|
||
|
// 'cash' => 'money',
|
||
|
// );
|
||
|
// $this->sign = array('username', 'orderNumber', 'number', 'productNo', 'money', 'orderTime', 'privateKey');
|
||
|
// $this->api = 'api/receiveOrder';
|
||
|
// return $this->submit($param, $check);
|
||
|
// }
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'phone',
|
||
|
'cash' => 'amount',
|
||
|
'type' => 'type',
|
||
|
);
|
||
|
$param['type'] = '2';
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
// $param['type']= $param['isp'];
|
||
|
if($param['isp'] == 1){
|
||
|
$param['type']= 2;
|
||
|
}elseif ($param['isp'] == 2){
|
||
|
$param['type']= 1;
|
||
|
}else{
|
||
|
$param['type']= 3;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
$this->api = 'api/receiveOrder';
|
||
|
// $this->sign = array('partner_id', 'partner_order_no' ,'phone','amount','');
|
||
|
$this->sign = array('partner_id', 'partner_order_no', 'phone', 'amount', 'type', 'notify_url','privateKey');
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
|
||
|
// $check = array
|
||
|
// (
|
||
|
// 'mobile' => 'phone',
|
||
|
// 'cash' => 'amount',
|
||
|
// );
|
||
|
|
||
|
//
|
||
|
// return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 订单查询
|
||
|
public function ddcx($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'partner_order_no' => 'string',
|
||
|
|
||
|
);
|
||
|
$this->sign = array('partner_id', 'partner_order_no');
|
||
|
$this->api = 'api/queryOrder';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 取消订单
|
||
|
public function qxdd($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'partner_order_no' => 'string'
|
||
|
);
|
||
|
$this->sign = array('partner_id', 'partner_order_no');
|
||
|
$this->api = 'api/cancelOrder';
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
// $request = $data;
|
||
|
$result = array();
|
||
|
// $result['status'] = 4;
|
||
|
$result['cash'] = 1;
|
||
|
|
||
|
if ($data['status'] == 1) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['status'] == -1) {
|
||
|
$result['status'] = 3;
|
||
|
} elseif ($data['status'] == 0) {
|
||
|
//存疑
|
||
|
$result['status'] = 5;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
$msg = '';
|
||
|
if (isset($data['official_order_no']) && $data['official_order_no']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['official_order_no'];
|
||
|
}
|
||
|
|
||
|
|
||
|
$result['yes'] = 'success';
|
||
|
|
||
|
$result['data'] = $data;
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
# 数据响应格式处理
|
||
|
public function response($data)
|
||
|
{
|
||
|
$log['type'] = 'response';
|
||
|
$log['data'] = $data;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
$array = $this->json_decode($data);
|
||
|
if (!$array) {
|
||
|
$msg = 'error';
|
||
|
} elseif (isset($array['code']) && $array['code'] == '1') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
}
|
||
|
// elseif (isset($array['status']) && $array['status'] == '101') {
|
||
|
// # 疑似
|
||
|
// $msg = 'ys';
|
||
|
// } elseif (isset($array['status']) && $array['status'] == '122616') {
|
||
|
// # 疑似
|
||
|
// $msg = 'ys';
|
||
|
// }
|
||
|
else {
|
||
|
# 错误
|
||
|
$msg = isset($array['desc']) ? $array['desc'] : 'error';
|
||
|
}
|
||
|
|
||
|
# 增加卡密日志
|
||
|
$order = array();
|
||
|
if ($this->order_id) {
|
||
|
$order = OrderService::instance()->get($this->order_id);
|
||
|
|
||
|
if ($order && $order['card_id'] > 0) {
|
||
|
if ($msg == 'ok') {
|
||
|
CardService::instance()->log($order, 3, '渠道下单成功');
|
||
|
} else {
|
||
|
CardService::instance()->log($order, 4, '渠道下单失败');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public function encrypt($value, $key = false, $iv = false)
|
||
|
{
|
||
|
if (!$key) {
|
||
|
//$key = str_replace('-', '', $this->token);
|
||
|
$key = $this->token;
|
||
|
$iv = substr($key, -16, 16);
|
||
|
$key = substr($key, 0, 16);
|
||
|
}
|
||
|
$data = openssl_encrypt($value, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv);
|
||
|
$data = base64_encode($data);
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
public function query($param)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
private function submit($param, $check)
|
||
|
{
|
||
|
$param = $this->param($param, $check);
|
||
|
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
|
return $param;
|
||
|
}
|
||
|
// var_dump($param);exit;
|
||
|
// $request = $param['detail'];
|
||
|
$request['partner_id'] = $this->mid;
|
||
|
$this->order_id = $request['partner_order_no'] = $param['order'];
|
||
|
$request['phone'] = $param['detail']['phone'];
|
||
|
$request['amount'] = $param['detail']['amount'];
|
||
|
$request['type'] = $param['detail']['type'];
|
||
|
// $request['orderTime'] = date('Y-m-d H:i:s');
|
||
|
// $request['type']=$this->lprefix;
|
||
|
$request['notify_url'] = $this->getNotify($param['order'], 1);
|
||
|
// $request['amount']=$param['cash'];
|
||
|
// $request['phone']=$param['account'];
|
||
|
$request['sign'] = $this->_sign($request, $this->sign);
|
||
|
// var_dump($request);exit;
|
||
|
|
||
|
// if (isset($request['cardNum']) && $request['cardNum']) {
|
||
|
// $request['cardNum'] = $this->encrypt($request['cardNum']);
|
||
|
// }
|
||
|
// if (isset($request['cardPwd']) && $request['cardPwd']) {
|
||
|
// $request['cardPwd'] = $this->encrypt($request['cardPwd']);
|
||
|
// }
|
||
|
|
||
|
|
||
|
|
||
|
$url = $this->host . $this->api;
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = '';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
/*
|
||
|
if (isset($response['array']['obj']) && $response['array']['obj']) {
|
||
|
$channel_order_id = $response['array']['obj'];
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], '', $this->card_id);
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
|
||
|
|
||
|
private function _sign($request, $param)
|
||
|
{
|
||
|
$request['privateKey'] = $this->token;
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $request[$v];
|
||
|
}
|
||
|
}
|
||
|
// var_dump($signature_string);exit;
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
|
||
|
private function getCode($prefix, $cash)
|
||
|
{
|
||
|
return $prefix . $cash;
|
||
|
}
|
||
|
}
|