186 lines
5.2 KiB
PHP
186 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Jinyu extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = '';
|
|
protected $mid = '';
|
|
protected $token = '';
|
|
protected $type = 4;
|
|
|
|
# 电话充值
|
|
public function dhcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'mobile' => 'acct',
|
|
'cash' => 'total',
|
|
//'op' => 'op',
|
|
);
|
|
/*
|
|
if (isset($param['isp']) && $param['isp']) {
|
|
if ($param['isp'] == 1) {
|
|
$param['cc'] = '';
|
|
}
|
|
}
|
|
*/
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石油油卡充值 拼音来吧
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'acct',
|
|
'cash' => 'total',
|
|
);
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'acct',
|
|
'cash' => 'total',
|
|
);
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['result'] == '0') {
|
|
$result['status'] = 2;
|
|
} elseif ($data['result'] == '9') {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
|
|
if (isset($data['voucherContent']) && $data['voucherContent']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucherContent'];
|
|
}
|
|
|
|
$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['result']) && $array['result'] == '0') {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
# 错误
|
|
$msg = isset($array['msg']) ? $array['msg'] : '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'];
|
|
$request['userId'] = $this->mid;
|
|
$request['orderId'] = $param['order'];
|
|
$request['rs'] = $this->rand(16);
|
|
$request['method'] = 'Charge.MobileCharge';
|
|
$request['ver'] = '1.0';
|
|
list($msec, $sec) = explode(' ', microtime());
|
|
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
|
$msec = substr($msectime,0,13);
|
|
$request['ts'] = $msec;
|
|
$request['notifyUrl'] = $this->getNotify($param['order'], 1);
|
|
$request['sign'] = $this->_sign($request);
|
|
$url = $this->host . 'Charge/MobileCharge';
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['requestId'])) {
|
|
$channel_order_id = $response['array']['requestId'];
|
|
}
|
|
|
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
|
return $response['msg'];
|
|
}
|
|
|
|
private function _sign($request)
|
|
{
|
|
ksort($request);
|
|
$signature_string = '';
|
|
foreach ($request as $k => $v) {
|
|
$signature_string .= $k . '=' . $v . '&';
|
|
}
|
|
|
|
$signature_string = rtrim($signature_string, '&');
|
|
|
|
return strtoupper(hash_hmac('sha1', $signature_string, $this->token));
|
|
}
|
|
|
|
public function rand($len, $type = 4)
|
|
{
|
|
$source = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
|
|
|
|
$config = array
|
|
(
|
|
0 => array("min" => 0, "max" => 9), /// 全数字
|
|
1 => array("min" => 10, "max" => 35), /// 全小写
|
|
2 => array("min" => 36, "max" => 61), /// 全大写
|
|
3 => array("min" => 10, "max" => 61), /// 大小写
|
|
4 => array("min" => 0, "max" => 61), /// 数字+大小写
|
|
);
|
|
if (!isset($config[$type])) {
|
|
$type = 4;
|
|
}
|
|
|
|
$rand = "";
|
|
for ($i = 0; $i < $len; $i++) {
|
|
$rand .= $source[rand($config[$type]["min"], $config[$type]["max"])];
|
|
}
|
|
|
|
return $rand;
|
|
}
|
|
} |