178 lines
4.9 KiB
PHP
178 lines
4.9 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
|
||
|
/**
|
||
|
* 话费服务
|
||
|
* Class Common
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Yigu extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
|
||
|
# 电话充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'account',
|
||
|
'cash' => 'price',
|
||
|
'carrier' => 'carrier',
|
||
|
'product' => 'product',
|
||
|
);
|
||
|
$this->api = 'order.do';
|
||
|
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
$isp = $param['isp'];
|
||
|
} else {
|
||
|
$isp = $this->isp($request['mobile']);
|
||
|
}
|
||
|
$param['carrier'] = $isp;
|
||
|
$param['product'] = 'fee';
|
||
|
$this->sign = array('product', 'productid', 'userid', 'price', 'num', 'account', 'spordertime', 'sporderid', 'carrier');
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function zshcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'card' => 'account',
|
||
|
'cash' => 'price',
|
||
|
'product' => 'product',
|
||
|
);
|
||
|
$this->api = 'order.do';
|
||
|
$param['product'] = 'sinopec';
|
||
|
$this->sign = array('product', 'userid', 'price', 'num', 'account', 'spordertime', 'sporderid');
|
||
|
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
unset($request['sign']);
|
||
|
unset($request['s_order']);
|
||
|
$sign = strtoupper($this->_sign($request, array('userid', 'orderid', 'sporderid', 'merchantsubmittime', 'resultno')));
|
||
|
if ($sign != $data['sign']) {
|
||
|
return false;
|
||
|
}
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['resultno'] == 1) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['resultno'] == 9) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
if (isset($data['cert']) && $data['cert']) {
|
||
|
# 流水号
|
||
|
if (strstr($data['cert'], '订单号:')) {
|
||
|
$temp = explode('订单号:', $data['cert']);
|
||
|
$data['msg'] = $result['msg'] = $data['cert'];
|
||
|
} else {
|
||
|
$temp[1] = $data['cert'];
|
||
|
}
|
||
|
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $temp[1];
|
||
|
}
|
||
|
|
||
|
$result['yes'] = 'OK';
|
||
|
|
||
|
$result['data'] = $data;
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
# 数据响应格式处理
|
||
|
public function response($data)
|
||
|
{
|
||
|
$log['type'] = 'response';
|
||
|
$log['data'] = $data;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
$array = (array) simplexml_load_string($data);
|
||
|
|
||
|
if (!$array) {
|
||
|
$msg = 'error';
|
||
|
} elseif (isset($array['resultno']) && $array['resultno'] == '0') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = 'error';
|
||
|
}
|
||
|
|
||
|
return array
|
||
|
(
|
||
|
'msg' => $msg,
|
||
|
'data' => $array,
|
||
|
'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['num'] = 1;
|
||
|
$request['productid'] = '';
|
||
|
$request['userid'] = $this->mid;
|
||
|
$request['sporderid'] = $param['order'];
|
||
|
$request['spordertime'] = date('YmdHis');
|
||
|
$request['back_url'] = $this->getNotify($param['order'], 1);
|
||
|
|
||
|
if ($request['product'] == 'fee') {
|
||
|
$request['productid'] = $this->getGid($param['cash']);
|
||
|
}
|
||
|
|
||
|
|
||
|
$request['sign'] = $this->_sign($request, $this->sign);
|
||
|
$url = $this->host . $this->api;
|
||
|
$response = $this->curl('post', $url, $request);
|
||
|
$response = $this->response($response);
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['orderid'])) {
|
||
|
$channel_order_id = $response['array']['orderid'];
|
||
|
}
|
||
|
|
||
|
$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, $param)
|
||
|
{
|
||
|
//ksort($request);
|
||
|
$signature_string = '';
|
||
|
foreach ($param as $k => $v) {
|
||
|
if (isset($request[$v])) {
|
||
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$signature_string .= 'key=' . $this->token;
|
||
|
|
||
|
return md5($signature_string);
|
||
|
}
|
||
|
}
|