172 lines
4.5 KiB
PHP
172 lines
4.5 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 平安服务
|
||
|
* Class Tiancheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Pingan extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'http://47.118.58.136/';
|
||
|
protected $mid = '83027';
|
||
|
protected $token = 'ca410867c9bad558a';
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'mobile',
|
||
|
'cash' => 'amount',
|
||
|
'type' => 'type',
|
||
|
);
|
||
|
$param['type'] = 1;
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石油油卡充值 拼音来吧
|
||
|
public function zsycz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'mobile',
|
||
|
'cash' => 'amount',
|
||
|
'type' => 'type',
|
||
|
'op' => 'op',
|
||
|
);
|
||
|
$param['op'] = 5;
|
||
|
$param['type'] = 4;
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'mobile',
|
||
|
'cash' => 'amount',
|
||
|
'type' => 'type',
|
||
|
'op' => 'op',
|
||
|
);
|
||
|
$param['op'] = 5;
|
||
|
$param['type'] = 4;
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
unset($request['s_order']);
|
||
|
$sign = $this->_sign($request);
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = floatval($data['amount']);
|
||
|
if ($data['status'] == 'success') {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['status'] == 'failed') {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
$result['yes'] = 'success';
|
||
|
|
||
|
if (isset($data['sz_order_no']) && $data['sz_order_no']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['sz_order_no'];
|
||
|
}
|
||
|
|
||
|
$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['status']) && $array['status'] == 0) {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = $array['msg'];
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $data,
|
||
|
'array' => $array,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
# 提交数据
|
||
|
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['cpid'] = $this->mid;
|
||
|
$request['ret_para'] = $param['order'];
|
||
|
$request['create_time'] = date('YmdHis');
|
||
|
$request['product_id'] = $this->product($param);
|
||
|
//$request['notifyurl'] = $this->getNotify($param['order'], 1);
|
||
|
$request['sign'] = $this->_sign($request);
|
||
|
$url = $this->host . 'api/do';
|
||
|
$response = $this->curl('get', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
//$response['data'] = 'ttt';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['order_no'])) {
|
||
|
$channel_order_id = $response['array']['order_no'];
|
||
|
}
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
|
||
|
# 获取产品id
|
||
|
private function product($param)
|
||
|
{
|
||
|
if ($param['cash'] == 100) {
|
||
|
return '20032';
|
||
|
} elseif ($param['cash'] == 200) {
|
||
|
return '20033';
|
||
|
} elseif ($param['cash'] == 500) {
|
||
|
return '20034';
|
||
|
} elseif ($param['cash'] == 1000) {
|
||
|
return '20035';
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
private function _sign($request)
|
||
|
{
|
||
|
ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($request as $k => $v) {
|
||
|
$signature_string .= $k . $v;
|
||
|
}
|
||
|
|
||
|
$signature_string .= $this->token;
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
}
|