158 lines
4.6 KiB
PHP
158 lines
4.6 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
use app\channel\service\CardService;
|
||
|
/**
|
||
|
* 收卡服务
|
||
|
* Class Shoukala
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Cheyoumashouka extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
protected $aes = 'awakuoy';
|
||
|
protected $card = array();
|
||
|
protected $sign = array();
|
||
|
|
||
|
# 中石化收卡
|
||
|
public function zshsk($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'CardNo',
|
||
|
'pwd' => 'CardPwd',
|
||
|
'cash' => 'FaceValue',
|
||
|
'percent' => 'TradeAmount',
|
||
|
'card_id' => 'card_id',
|
||
|
);
|
||
|
if (!isset($param['card_id'])) {
|
||
|
$data = CardService::instance()->getOne($param['card'], $param['pwd']);
|
||
|
if ($data) {
|
||
|
$param['card_id'] = $data['id'];
|
||
|
}
|
||
|
}
|
||
|
$this->card_id = $param['card_id'];
|
||
|
$this->CardType = 1;
|
||
|
$this->CardOperator = 11;
|
||
|
$this->api = 'API/CollectCardApi/Submit';
|
||
|
$this->sign = array('MerchantID', 'CardType', 'CardOperator', 'FaceValue', 'TradeAmount', 'CardNo', 'CardPwd', 'OutOrderNo', 'StartTime', 'NotifyUrl');
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$sign = $this->_sign($request, array('CardStatus', 'OutOrderNo', 'OrderNo', 'TradeAmount', 'Message', 'Timestamp'));
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['CardStatus'] == 2) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['CardStatus'] == 3) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
$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['ErrorCode']) && $array['ErrorCode'] == '0') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['Message']) ? $array['Message'] : 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 查询接口
|
||
|
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;
|
||
|
}
|
||
|
$request = $param['detail'];
|
||
|
unset($request['card_id']);
|
||
|
$request['CardPwd'] = $this->aes($request['CardPwd']);
|
||
|
$request['MerchantID'] = $this->mid;
|
||
|
$request['CardType'] = $this->CardType;
|
||
|
$request['CardOperator'] = $this->CardOperator;
|
||
|
$request['StartTime'] = date('Y-m-d H:i:s');
|
||
|
$request['OutOrderNo'] = $param['order'];
|
||
|
$request['NotifyUrl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['Sign'] = $this->_sign($request, $this->sign);
|
||
|
$request['CardPwd'] = urlencode($request['CardPwd']);
|
||
|
$url = $this->host . $this->api;
|
||
|
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['Data']['OrderNo'])) {
|
||
|
$channel_order_id = $response['array']['Data']['OrderNo'];
|
||
|
}
|
||
|
|
||
|
$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)
|
||
|
{
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v]) && $request[$v]) {
|
||
|
$signature_string .= $request[$v];
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= $this->token;
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
|
||
|
private function aes($data)
|
||
|
{
|
||
|
$key = md5($this->aes);
|
||
|
$key = substr($key, 8, 16);
|
||
|
|
||
|
$data = openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
|
||
|
return base64_encode($data);
|
||
|
}
|
||
|
}
|