175 lines
5.0 KiB
PHP
175 lines
5.0 KiB
PHP
<?php
|
||
|
||
namespace app\channel\service\system;
|
||
|
||
/**
|
||
* 八达通服务
|
||
* Class Badatong
|
||
* @package app\channel\service
|
||
*/
|
||
class Badatong extends Core
|
||
{
|
||
# 这几个可以后台设置
|
||
protected $host = 'https://api.zhenniupay.com/';
|
||
protected $mid = '11505';
|
||
protected $token = '67d5647d1cb3e5066f8c53567a922cdb';
|
||
|
||
# 电话充值
|
||
public function dhcz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
# key值是传入的数据,value是传出的数据
|
||
'mobile' => 'accountNumber',
|
||
'cash' => 'amount',
|
||
);
|
||
return $this->submit(29, $param, $check);
|
||
}
|
||
|
||
# 中石油油卡充值 拼音来吧
|
||
public function zsycz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'card' => 'accountNumber',
|
||
'cash' => 'amount',
|
||
'mobile' => 'phone',
|
||
'idCard' => 'idCard',
|
||
'realName' => 'realName',
|
||
);
|
||
return $this->submit(27, $param, $check);
|
||
}
|
||
|
||
# 中石化油卡充值
|
||
public function zshcz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'card' => 'accountNumber',
|
||
'cash' => 'amount',
|
||
//'mobile' => 'phone',
|
||
);
|
||
return $this->submit(12, $param, $check);
|
||
}
|
||
|
||
# 电费卡充值
|
||
public function dfcz($param)
|
||
{
|
||
$check = array
|
||
(
|
||
'card' => 'accountNumber',
|
||
'cash' => 'amount',
|
||
'city' => 'city',
|
||
'provider' => 'provider',
|
||
);
|
||
return $this->submit(19, $param, $check);
|
||
}
|
||
|
||
# 通知处理 主要返回状态 2是成功 3是失败
|
||
public function notify($data)
|
||
{
|
||
//$data = file_get_contents("php://input");
|
||
//$data = json_decode($data, true);
|
||
$request = $data;
|
||
unset($request['sign']);
|
||
unset($request['s_order']);
|
||
unset($request['s_type']);
|
||
unset($request['official_serial_number']);
|
||
unset($request['supplier_store']);
|
||
$request['amount'] = str_replace(',', '', number_format($request['amount'], 2));
|
||
$sign = $this->sign($request, 'md5', '&token=' . $this->token . '&');
|
||
if ($sign != $data['sign']) {
|
||
return false;
|
||
}
|
||
|
||
$result = array();
|
||
//$result['data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||
$result['data'] = $data;
|
||
$result['cash'] = floatval($data['amount']);
|
||
if ($data['status'] == 3) {
|
||
$result['status'] = 2;
|
||
} else {
|
||
$result['status'] = 3;
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
# 数据响应格式处理
|
||
public function response($data)
|
||
{
|
||
$log['type'] = 'response';
|
||
$log['data'] = $data;
|
||
$log['config'] = $this->data;
|
||
$this->log($log);
|
||
|
||
$array = $this->json_decode($data);
|
||
if (!$array) {
|
||
$msg = 'error';
|
||
} elseif (isset($array['success']) && $array['success'] && isset($array['data']) && $array['data']) {
|
||
$msg = 'ok';
|
||
} else {
|
||
$msg = $array['status_msg'];
|
||
}
|
||
|
||
return array
|
||
(
|
||
'msg' => $msg,
|
||
'data' => $data,
|
||
'array' => $array,
|
||
);
|
||
}
|
||
|
||
# 查询接口 (未调试)
|
||
public function query($param)
|
||
{
|
||
if (empty($param['order'])) {
|
||
return 'order';
|
||
}
|
||
$request['order_no'] = $param['order'];
|
||
if (isset($param['account_number'])) {
|
||
$request['account_number'] = $param['account_number'];
|
||
}
|
||
|
||
$request['sign'] = $this->sign($request, 'md5', '&token=' . $this->token . '&');
|
||
|
||
$headers['merchant_id'] = $this->mid;
|
||
$headers['api-token'] = $this->token;
|
||
$url = $this->host . 'api/recharge/query';
|
||
return $this->response($this->curl('post', $url, $request, false, $headers));
|
||
}
|
||
|
||
# 提交数据
|
||
private function submit($id, $param, $check)
|
||
{
|
||
$param = $this->param($param, $check);
|
||
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
return $param;
|
||
}
|
||
|
||
$param['detail'] = array($param['detail']);
|
||
$request['merchant_id'] = $this->mid;
|
||
$request['order_no'] = $param['order'];
|
||
$request['product_id'] = $id;
|
||
$request['notify_url'] = $this->getNotify($param['order'], 2);
|
||
|
||
$request['sign'] = $this->sign($request, 'md5', '&token=' . $this->token . '&');
|
||
$request['recharge_detail'] = $param['detail'];
|
||
|
||
$headers['merchant_id'] = $this->mid;
|
||
$headers['api-token'] = $this->token;
|
||
$url = $this->host . 'api/recharge/order';
|
||
|
||
$response = $this->curl('post', $url, $request, true, $headers);
|
||
$response = $this->response($response);
|
||
|
||
$channel_order_id = '';
|
||
if (isset($response['array']['data']['serial_number'])) {
|
||
$channel_order_id = $response['array']['data']['serial_number'];
|
||
}
|
||
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||
return $response['msg'];
|
||
}
|
||
|
||
#
|
||
} |