REAPI/app/channel/service/system/Hypermarket.php.bak

364 lines
9.2 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\channel\service\system;
/**
* 福斯特话费服务
* Class Common
* @package app\channel\service
*/
class Foster extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
protected $paytype = '';
# 通用的充值
public function common($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
);
$this->paytype = '';
return $this->submit($param, $check);
}
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = '';
return $this->submit($param, $check);
}
# 电信
public function dxcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'dx';
return $this->submit($param, $check);
}
# 移动充值
public function ydcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'yd';
return $this->submit($param, $check);
}
# 联通充值
public function ltcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'lt';
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'ZSY';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'mobile',
'cash' => 'price',
);
$this->api = 'onlinepay.do';
$this->paytype = 'ZSH';
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['remark1']) && $data['remark1']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['remark1'];
}
$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)
{
$request['szAgentId'] = $this->mid;
$request['szOrderId'] = $order['order_id'];
$request['szVerifyString'] = $this->_sign1($request, array('szAgentId', 'szOrderId'));
$request['szFormat'] = 'json';
$url = $this->host . 'api/old/queryorder';
$response = $this->curl('post', $url, $request);
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
$array = $this->json_decode($response);
$result = array();
$result['status'] = 4;
if (isset($array['nRtn']) ) {
if($array['nRtn'] == '5012'){
$result['nFlag'] = 2;
$result['status'] = 2;
}elseif ($array['nRtn'] == '5013'){
$result['nFlag'] = 3;
$result['status'] = 3;
}
if (isset($array['szRtnMsg']) && $array['szRtnMsg']) {
# 流水号
// $data['szRtnMsg']
$result['szRtnMsg'] = $array['szRtnMsg'];
}
}
return $result;
}
# 提交数据
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 ($this->paytype) {
$request['paytype'] = $this->paytype;
$request['productid'] = $this->getCode($param['cash']);
if (!$request['productid']) {
return 'order';
}
} else {
if (isset($param['isp']) && $param['isp']) {
$isp = $param['isp'];
} else {
$isp = $this->isp($request['mobile']);
}
$paytype = '';
if ($isp == 1) {
$paytype = 'yd';
}
if ($isp == 2) {
$paytype = 'lt';
}
if ($isp == 3) {
$paytype = 'dx';
}
$request['paytype'] = $paytype;
$productid = $this->getDhczCode($paytype,$param['cash']);
if ($productid && $productid != -1) {
$request['productid'] = $productid;
}
}
$request['sign'] = $this->_sign($request, array('userid', 'productid', 'price', 'num', 'mobile', 'spordertime', 'sporderid'));
$url = $this->host . $this->api;
$response = $this->curl('get', $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 getCode($cash)
{
if ($this->paytype == 'ZSH') {
if ($cash == 100) {
return 30000001050;
} elseif ($cash == 200) {
return 30000001051;
} elseif ($cash == 500) {
return 30000001053;
} elseif ($cash == 1000) {
return 30000001054;
} elseif ($cash == 2000) {
return 40000001090;
}
} else {
if ($cash == 100) {
return 40000001070;
} elseif ($cash == 200) {
return 40000001071;
} elseif ($cash == 500) {
return 40000001072;
} elseif ($cash == 1000) {
return 40000001073;
}
}
return false;
}
private function getDhczCode($paytype,$cash)
{
if ($paytype == 'yd') {
if ($cash == 30) {
return 30000000908;
} elseif ($cash == 50) {
return 30000000909;
} elseif ($cash == 100) {
return 30000000910;
} elseif ($cash == 200) {
return 30000000911;
}
} elseif ($paytype == 'lt') {
if ($cash == 30) {
return 30000000731;
} elseif ($cash == 50) {
return 30000000732;
} elseif ($cash == 100) {
return 30000000733;
} elseif ($cash == 200) {
return 30000000992;
}
} else {
if ($cash == 50) {
return 101724;
} elseif ($cash == 100) {
return 101725;
} elseif ($cash == 200) {
return 101726;
}
}
return false;
}
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);
}
}