151 lines
4.4 KiB
PHP
151 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace app\channel\service\system;
|
|
|
|
/**
|
|
* 合肥趣传 售卡服务
|
|
* Class Shouka
|
|
* @package app\channel\service
|
|
*/
|
|
class Shouka extends Core
|
|
{
|
|
# 这几个可以后台设置
|
|
protected $host = 'http://api.91shouka.com/';
|
|
protected $mid = '800262';
|
|
protected $token = '90B87B208ADC086D';
|
|
protected $method = '';
|
|
|
|
# 中石油油卡充值 拼音来吧
|
|
public function zsycz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'TargetAccount',
|
|
'cash' => 'Parvalue',
|
|
'ProductID' => 'ProductID',
|
|
);
|
|
$param['ProductID'] = 'zsh0100';
|
|
$this->method = 'OrderCharge.do';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 中石化油卡充值
|
|
public function zshcz($param)
|
|
{
|
|
$check = array
|
|
(
|
|
'card' => 'TargetAccount',
|
|
'cash' => 'Parvalue',
|
|
'ProductID' => 'ProductID',
|
|
);
|
|
$param['ProductID'] = 'zsh0100';
|
|
$this->method = 'OrderCharge.do';
|
|
return $this->submit($param, $check);
|
|
}
|
|
|
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|
public function notify($data)
|
|
{
|
|
$request = $data;
|
|
$sign = $this->_sign($request['OrderID'] . $request['MerchantOrderID'] . $request['State']);
|
|
if ($sign != $data['Sign']) {
|
|
return false;
|
|
}
|
|
$result = array();
|
|
$result['cash'] = 1;
|
|
if ($data['State'] == 1) {
|
|
$result['status'] = 2;
|
|
} elseif ($data['State'] == 2) {
|
|
$result['status'] = 3;
|
|
} else {
|
|
$result['status'] = 4;
|
|
}
|
|
if (isset($data['Number']) && $data['Number']) {
|
|
# 流水号
|
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['Number'];
|
|
}
|
|
|
|
$result['data'] = $data;
|
|
|
|
$result['yes'] = 'OK';
|
|
|
|
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'] == '000') {
|
|
$array['order'] = (array) $array['order'];
|
|
if (isset($array['order']['orderid']) && $array['order']['orderid']) {
|
|
# 正确
|
|
$msg = 'ok';
|
|
} else {
|
|
$msg = isset($array['retmsg']) ? $array['retmsg'] : 'error';
|
|
}
|
|
} else {
|
|
# 错误
|
|
$msg = isset($array['retmsg']) ? $array['retmsg'] : '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['Parvalue'] = intval($request['Parvalue']);
|
|
|
|
$num=str_pad($request['Parvalue'],4,"0",STR_PAD_LEFT);
|
|
$request['ProductID'] = 'zsh'.$num;
|
|
$request['MerchantID'] = $this->mid;
|
|
$request['MerchantOrderID'] = $param['order'];
|
|
$request['BuyAmount'] = 1;
|
|
$request['CustomerIP'] = '106.75.218.165';
|
|
$request['NotifyUrl'] = $this->getUrl('/gateway/api.notify/shouka');
|
|
$request['Sign'] = $this->_sign($request['MerchantID'] . $request['MerchantOrderID'] . $request['ProductID'] . $request['Parvalue'] . $request['BuyAmount'] . $request['TargetAccount']);
|
|
$url = $this->host . $this->method;
|
|
$response = $this->curl('get', $url, $request);
|
|
$response = $this->response($response);
|
|
//$response['data'] = '{}';
|
|
//$response['msg'] = 'ok';
|
|
$channel_order_id = '';
|
|
if (isset($response['array']['order']['orderid'])) {
|
|
$channel_order_id = $response['array']['order']['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($string)
|
|
{
|
|
return strtoupper(md5($string . $this->token));
|
|
}
|
|
} |