141 lines
3.8 KiB
PHP
141 lines
3.8 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\channel\service\system;
|
||
|
require(__DIR__ . "/../extend/sdk/banma/OpenSdk.php");
|
||
|
|
||
|
/**
|
||
|
* 服务
|
||
|
* Class Bodingcheng
|
||
|
* @package app\channel\service
|
||
|
*/
|
||
|
class Banma extends Core
|
||
|
{
|
||
|
# 这几个可以后台设置
|
||
|
protected $host = 'host';
|
||
|
protected $mid = 'mid';
|
||
|
protected $token = 'token';
|
||
|
protected $api = 'api';
|
||
|
protected $itemId = 'OIL';
|
||
|
|
||
|
# 中石化油卡充值
|
||
|
public function dhcz($param)
|
||
|
{
|
||
|
$check = array
|
||
|
(
|
||
|
'mobile' => 'mobileNo',
|
||
|
'cash' => 'rechargeAmount',
|
||
|
'payType' => 'payType',
|
||
|
);
|
||
|
$param['payType'] = 'MOBILE';
|
||
|
if (isset($param['isp']) && $param['isp']) {
|
||
|
if ($param['isp'] == 1) {
|
||
|
$param['payType'] = 'MOBILE';
|
||
|
} elseif ($param['isp'] == 2) {
|
||
|
$param['payType'] = 'UNICOM';
|
||
|
} elseif ($param['isp'] == 3) {
|
||
|
$param['payType'] = 'TELECOM';
|
||
|
}
|
||
|
}
|
||
|
return $this->submit($param, $check);
|
||
|
}
|
||
|
|
||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||
|
public function notify($data)
|
||
|
{
|
||
|
$request = $data;
|
||
|
$result = array();
|
||
|
$result['cash'] = 1;
|
||
|
if ($data['recharge_state'] == 1) {
|
||
|
$result['status'] = 2;
|
||
|
} elseif ($data['recharge_state'] == 9) {
|
||
|
$result['status'] = 3;
|
||
|
} else {
|
||
|
$result['status'] = 4;
|
||
|
}
|
||
|
|
||
|
if (isset($data['voucher']) && $data['voucher']) {
|
||
|
# 流水号
|
||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['voucher'];
|
||
|
}
|
||
|
|
||
|
$result['data'] = $data;
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
# 数据响应格式处理
|
||
|
public function response($data)
|
||
|
{
|
||
|
$log['type'] = 'response';
|
||
|
$log['data'] = $data;
|
||
|
$log['config'] = $this->data;
|
||
|
$this->log($log);
|
||
|
|
||
|
if (is_object($data)) {
|
||
|
$array = (array) $data;
|
||
|
$data = $array;
|
||
|
} elseif (is_array($data)) {
|
||
|
$array = $data;
|
||
|
} elseif(is_string($data) && strstr($data, '{')) {
|
||
|
$array = $this->json_decode($data);
|
||
|
} else {
|
||
|
$array['message'] = $data;
|
||
|
}
|
||
|
|
||
|
if (!$array) {
|
||
|
$msg = 'error';
|
||
|
} elseif (isset($array['payState']) && $array['payState'] == '1') {
|
||
|
# 正确
|
||
|
$msg = 'ok';
|
||
|
} else {
|
||
|
# 错误
|
||
|
$msg = isset($array['message']) ? $array['message'] : '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'];
|
||
|
|
||
|
$client = new \OpenClient;
|
||
|
$key = explode('|', $this->mid);
|
||
|
$client->appKey = $key[0];
|
||
|
$client->appSecret = $key[1];
|
||
|
$accessToken = $this->token;
|
||
|
$req = new \BmRechargeMobilePayBillRequest;
|
||
|
$req->setOuterTid($param['order']);
|
||
|
$req->setCallback($this->getNotify($param['order'], 1));
|
||
|
$req->setMobileNo($request['mobileNo']);
|
||
|
$req->setRechargeAmount($request['rechargeAmount']);
|
||
|
$response = $client->execute($req, $accessToken);
|
||
|
$response = $this->response($response);
|
||
|
$url = '';
|
||
|
//$response['data'] = '';
|
||
|
//$response['msg'] = 'ok';
|
||
|
$channel_order_id = '';
|
||
|
if (isset($response['array']['data']['billId'])) {
|
||
|
$channel_order_id = $response['data']['billId'];
|
||
|
}
|
||
|
|
||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
|
return $response['msg'];
|
||
|
}
|
||
|
}
|