REAPI/app/channel/service/system/Meicheng.php
b3f70a8d30 feat(queue): 新增临时锁卡任务
- 添加 LinSuoKa 类实现临时锁卡功能
- 优化卡密订单关联逻辑,处理状态为 4 的订单- 新增 redis 记录订单详情,用于限单和退款处理
- 修改 Qiling 类中的签名生成逻辑
- 更新 Test 控制器中的 test_ts 方法,增加对不同订单表的处理
2025-06-03 18:55:03 +08:00

268 lines
7.1 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 话费服务
* Class Common
* @package app\channel\service
*/
class Meicheng extends Core
{
# 这几个可以后台设置
protected $host = 'host';
protected $mid = 'mid';
protected $token = 'token';
protected $api = 'api';
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
'paytype' => 'paytype',
);
$this->api = 'onlinepay.do';
if (isset($param['isp']) && $param['isp']) {
$isp = $param['isp'];
} else {
$isp = $this->isp($param['mobile']);
}
$paytype = '';
if ($isp == 1) {
$paytype = 'yd';
}
if ($isp == 2) {
$paytype = 'lt';
}
if ($isp == 3) {
$paytype = 'dx';
}
$param['paytype'] = $paytype;
return $this->submit($param, $check);
}
public function ydcz($param)
{
$param['paytype'] = 'yd';
return $this->hf_submit($param);
}
public function ltcz($param)
{
$param['paytype'] = 'lt';
return $this->hf_submit($param);
}
public function ltcz_mini($param)
{
$param['paytype'] = 'lt';
return $this->hf_submit($param);
}
public function dxcz($param)
{
$param['paytype'] = 'dx';
return $this->hf_submit($param);
}
public function dxcz_lt_mnp($param)
{
$param['paytype'] = 'dx';
return $this->hf_submit($param);
}
public function hf_submit($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'price',
'paytype' => 'paytype',
's_num'=>'num'
);
$param['s_num'] = 1;
$this->api = 'onlinepay.do';
return $this->submit($param, $check);
}
# 查询余额接口
public function account()
{
// $request['day'] = $day;
$request['userid'] = $this->mid;
$request['sign'] = $this->_sign($request, array('userid'));
$url = $this->host . 'searchbalance.do';
$response = $this->curl('get', $url, $request);
// var_dump($response);die;
$log['type'] = 'account_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
$array = (array) simplexml_load_string($response);
if (!$array) {
return false;
} elseif (isset($array['resultno']) && $array['resultno'] == '1') {
$array['account'] = $array['balance'];
# 正确
return $array;
} else {
# 错误
return false;
}
}
# 通知处理 主要返回状态 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(!isset($data['query_status']) ){
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_number'] = $result['s_number'] = $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['userid'] = $this->mid;
$request['sporderid'] = $param['order_id'];
$request['sign'] = $this->_sign($request, array('userid', 'sporderid'));
$url = $this->host . 'searchpay.do';
$response = $this->curl('get', $url, $request);
$log['type'] = 'query_response';
$log['data'] = $response;
$log['config'] = $this->data;
$this->log($log);
$array = (array) simplexml_load_string($response);
$result = array();
$result = $array;
$result['status'] = 4;
$result['query_status'] = 1;
if (isset($array['resultno']) ) {
if($array['resultno'] == '1'){
$result['status'] = 2;
}elseif ($array['resultno'] == '9'){
$result['status'] = 3;
}
}
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'] = $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);
$request['productid'] = $this->getGid($param['cash']);
$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'];
}
if (isset($response['array']['ordercash']) && $response['array']['ordercash']) {
#动态成本
$response['channel_cost'] = $response['array']['ordercash'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
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);
}
}