REAPI/app/channel/service/system/Cheyouma.php
2024-09-29 15:43:18 +08:00

182 lines
5.1 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* cheyouma服务
* Class Bodingcheng
* @package app\channel\service
*/
class Cheyouma extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
protected $youka_type = 1;
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
);
$this->youka_type = 2;
$this->api = 'IRecharge_Oil';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
);
$this->youka_type = 1;
$this->api = 'IRecharge_Oil';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
$sign = $this->_sign($request, array('UserNumber', 'InOrderNumber', 'OutOrderNumber', 'PayResult'));
if ($sign != $data['RecordKey']) {
return false;
}
$result = array();
$result['cash'] = 1;
if ($data['PayResult'] == 2) {
$result['status'] = 2;
} elseif ($data['PayResult'] == 3) {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
/*
if (isset($data['exchangeTraded']) && $data['exchangeTraded']) {
# 流水号
if (strstr($data['exchangeTraded'], '订单号:')) {
$temp = explode('订单号:', $data['exchangeTraded']);
} else {
$temp[1] = $data['exchangeTraded'];
}
$data['s_nubmer'] = $result['s_nubmer'] = $temp[1];
}
*/
$result['yes'] = '<?xml version="1.0" encoding="utf-8"?><Esaipay><Result>success</Result><Message>接收成功</Message></Esaipay>';
$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['Result']) && $array['Result'] == 'success') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['Remark']) ? $array['Remark'] : '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['ProId'] = $this->getCode($param['cash']);
if (!$request['ProId']) {
return 'order';
}
$request['PhoneNumber'] = $param['detail']['card'];
$request['UserNumber'] = $this->mid;
$request['OutOrderNumber'] = $param['order'];
$request['PayAmount'] = 1;
$request['StartTime'] = date('Y-m-d H:i:s');
$request['MobilePhoneNumber'] = 13800138000;
$request['TimeOut'] = 3600;
$request['CallBackUrl'] = $this->getNotify($param['order'], 1);
$request['RecordKey'] = $this->_sign($request, array('UserNumber', 'OutOrderNumber', 'ProId', 'PhoneNumber', 'MobilePhoneNumber', 'PayAmount', 'StartTime', 'TimeOut', 'Remark'));
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['InOrderNumber'])) {
$channel_order_id = $response['array']['InOrderNumber'];
}
$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 ($cash == 100) {
return 110040;
} elseif ($cash == 200) {
return 110041;
} elseif ($cash == 500) {
return 100013;
} elseif ($cash == 1000) {
return 100014;
}
return false;
}
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 .= $request[$v];
}
}
//$signature_string = substr($signature_string, 0, -1);
$signature_string .= $this->token;
return strtoupper(substr(md5($signature_string), 0, 16));
}
}