192 lines
5.2 KiB
PHP
192 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 香兰服务
|
|
* Class Bodingcheng
|
|
* @package app\channel\service
|
|
*/
|
|
class Xianglan extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'http://api.yxwnc.com/';
|
|
protected $mid = '2250';
|
|
protected $token = '096a9e546c841c07a70506e405141b96';
|
|
protected $cztype = 1;
|
|
|
|
# 中石油充值
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'account',
|
|
'cash' => 'rechargevalue',
|
|
'number' => 'number',
|
|
);
|
|
$param['number'] = 1;
|
|
$this->cztype = 2;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'account',
|
|
'cash' => 'rechargevalue',
|
|
'number' => 'number',
|
|
);
|
|
$param['number'] = 1;
|
|
$this->cztype = 1;
|
|
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$sign = $this->_sign($request, array('orderid', 'merchantid', 'status', 'code'));
|
|
if ($sign != $data['sign']) {
|
|
return false;
|
|
}
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['code'] == 8888) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['code'] == 8021) {
|
|
$result['status'] = 5;
|
|
} elseif ($data['code'] == '0000') {
|
|
$result['status'] = 4;
|
|
} else {
|
|
$result['status'] = 3;
|
|
}
|
|
if (isset($data['tradecode']) && $data['tradecode']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['tradecode'];
|
|
}
|
|
|
|
$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 = $this->json_decode($data);
|
|
$array = (array) simplexml_load_string($data);
|
|
if (!$array) {
|
|
$msg = 'error';
|
|
} elseif (isset($array['code']) && $array['code'] == '0000') {
|
|
# 正确
|
|
$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['goodcode'] = $this->getCode($param['cash']);
|
|
$request['merchantid'] = $this->mid;
|
|
$request['orderid'] = $param['order'];
|
|
$request['ip'] = '106.75.218.165';
|
|
$request['createtime'] = date('YmdHis');
|
|
$request['returnurl'] = $this->getNotify($param['order'], 1);
|
|
$request['sign'] = $this->_sign($request, array('merchantid', 'goodcode', 'createtime', 'account', 'orderid', 'number'));
|
|
$url = $this->host . 'pay/Pay.aspx';
|
|
|
|
$response = $this->curl('post', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '';
|
|
//$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'];
|
|
}
|
|
|
|
private function getCode($cash)
|
|
{
|
|
if ($this->cztype == 1) {
|
|
|
|
if ($cash == 50) {
|
|
return 660050;
|
|
} elseif ($cash == 100) {
|
|
return 660100;
|
|
} elseif ($cash == 200) {
|
|
return 660200;
|
|
} elseif ($cash == 500) {
|
|
return 660500;
|
|
} elseif ($cash == 1000) {
|
|
return 661000;
|
|
} elseif ($cash == 2000) {
|
|
return 662000;
|
|
}
|
|
|
|
} else {
|
|
if ($cash == 100) {
|
|
return 670100;
|
|
} elseif ($cash == 200) {
|
|
return 670200;
|
|
} elseif ($cash == 500) {
|
|
return 670500;
|
|
} elseif ($cash == 1000) {
|
|
return 671000;
|
|
} elseif ($cash == 2000) {
|
|
return 672000;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function _sign($request, $param)
|
|
{
|
|
ksort($request);
|
|
$signature_string = '';
|
|
foreach ($param as $k => $v) {
|
|
if (isset($request[$v]) && $request[$v]) {
|
|
$signature_string .= $v . '=' . $request[$v] . '&';
|
|
}
|
|
}
|
|
|
|
$signature_string = substr($signature_string, 0, -1);
|
|
|
|
$signature_string .= $this->token;
|
|
|
|
return md5($signature_string);
|
|
}
|
|
} |