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

130 lines
3.6 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 天诚亿发服务
* Class Tiancheng
* @package app\channel\service
*/
class Tiancheng extends Core
{
# 这几个可以后台设置
protected $host = 'http://home.ogrnkbh.cn/';
protected $mid = '10101';
protected $token = '625d3c437eb4be7ad99755ece0ae222f';
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount_limit',
'mobile' => 'mobile',
'idCard' => 'idCard',
'realName' => 'name',
'card_type' => 'card_type',
'shop_id' => 'shop_id',
);
$param['card_type'] = 1;
$param['shop_id'] = $this->shop();
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'cardNo',
'cash' => 'amount_limit',
//'mobile' => 'mobile',
'card_type' => 'card_type',
'shop_id' => 'shop_id',
);
$param['card_type'] = 2;
$param['shop_id'] = $this->shop();
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['sign']);
unset($request['s_order']);
$sign = $this->sign($request, 'md5', '&key=' . $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'] == 1) {
$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['code']) && $array['code'] == 0 && isset($array['message']) && $array['message'] == 'success') {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $array['message'];
}
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['user_id'] = $this->mid;
$request['order_no'] = $param['order'];
$request['notify_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->sign($request, 'md5', '&key=' . $this->token);
$url = $this->host . 'cashier/api/ykorder';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '';
//$response['msg'] = 'ok';
$channel_order_id = '';
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
}