REAPI/app/channel/service/system/Pikoudai.php
mzeros 20a9af6fd0 feat(channel): 添加查询余额功能并优化相关服务
- 在 Channel 控制器中添加 queryBalance 方法,用于查询渠道余额
- 在 Core 控制器中添加 curl 方法,用于发起 HTTP 请求
- 新增 Feedov 服务类,实现飞之度商户自动提单功能- 更新 Meicheng 服务类,添加账户余额查询接口
- 在前端页面添加查询余额按钮和相关事件处理逻辑
2024-12-20 16:14:52 +08:00

320 lines
8.2 KiB
PHP

<?php
namespace app\channel\service\system;
/**
* 皮口袋--易客通
* Class Pikoudai
* @package app\channel\service
*/
class Pikoudai extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $method = '';
protected $api = '';
# 电话充值 拼音来吧
public function dhcz($param)
{
if (isset($param['isp']) && $param['isp']) {
$isp = $param['isp'];
} else {
$isp = $this->isp($param['mobile']);
}
$isp_name = '';
if ($isp == 1) {
$isp_name = '移动';
}
if ($isp == 2) {
$isp_name = '联通';
}
if ($isp == 3) {
$isp_name = '电信';
}
$param['isp_name'] = $isp_name;
return $this->submit_hf_param($param);
}
#移动充值
public function ydcz($param)
{
$param['isp_name'] = '移动';
return $this->submit_hf_param($param);
}
#联通充值
public function ltcz($param)
{
$param['isp_name'] = '联通';
return $this->submit_hf_param($param);
}
#电信充值
public function dxcz($param)
{
$param['isp_name'] = '电信';
return $this->submit_hf_param($param);
}
#提交统一参数
public function submit_hf_param($param)
{
$check = array
(
'mobile' => 'equity_number',
'cash' => 'face_value',
'num' => 'num',
'isp_name' => 'isp_name'
);
if(empty($param['num'])){
$param['num'] = 1;
}
$this->api = 'api/order/phone';
return $this->submit($param, $check);
}
public function dy($param){
$param['product_no'] = 'DYB';
return $this->submit_xnb_param($param);
}
#虚拟币统一参数
public function submit_xnb_param($param)
{
$check = array
(
'cash'=>'charge_money',
'account' => 'equity_number',
// 'proid' => 'productCode',
);
return $this->submit($param, $check);
// return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['Sign']);
$request['Sign'] = $this->_sign($request);
/*if ($request['Sign'] != $data['Sign']) {
return false;
}*/
// unset($request['signature']);
$result = array();
$result['cash'] = 1;
if ($data['Status'] == 'Success') {
$result['status'] = 2;
} elseif ($data['Status'] == 'Failure') {
$result['status'] = 3;
} else {
$result['status'] = 4;
}
/*
if (isset($this->data['product_key']) && strstr($this->data['product_key'], '_tc') && isset($data['vnum']) && $data['vnum']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['vnum'];
}
*/
if (isset($data['ChannelExtraInfo']) && $data['ChannelExtraInfo']) {
# 流水号
$data['s_number'] = $result['s_number'] = $data['ChannelExtraInfo'];
}
if (isset($data['msg']) && $data['msg']) {
# 错误信息
$data['msg'] = $result['msg'] = $data['msg'];
}
// $result['data'] = $data;
$result['yes'] = 'success';
$result['data'] = $data;
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'] == 1000) {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = $array['info'] ?? 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$time=time();
$request=array(
'appid'=>$this->mid,
'version'=>'v4',
'product'=>'query',
'merchant_order_id'=>$order->order_id,
'nonce'=>$time.rand(0,9),
'time'=>$time,
);
$request['sign']=$this->_sign($request);
#
$url = $this->host . 'handle/order';
$response = $this->curl('post', $url, $request,true);
$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['data']['status']) && $array['code'] == 1 ) {
if($array['status'] == '2'){
// $result['nFlag'] = 2;
$result['status'] = 2;
}elseif ($array['status'] == '3'){
// $result['nFlag'] = 3;
$result['status'] = 3;
}
if (isset($array['number']) && $array['number']) {
# 流水号
// $data['szRtnMsg']
$result['number'] = $array['data']['number'];
}
}
return $result;
}
# 查询余额接口
public function account($day)
{
$request['merchant_no'] = $this->mid;
$milliseconds = floor(microtime(true) * 1000);
$request['timestamp'] = strval($milliseconds); // 将时间戳转换为字符
$request['sign'] = $this->_sign($request);
$url = $this->host . 'api/merchant/balance';
$response = $this->curl('post', $url, $request,true);
$response = $this->response($response);
$datas = $response['array']['data'];
if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){
$datas['account'] = $datas['balance'];
}
return $datas;
}
# 提交数据
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['merchant_no'] = $this->mid;
$request['merchant_order_no'] = $param['order'];
// if(isset($this->product) && $this->product['key']){
// switch ($this->product['key']){
// case 'qbcz':
// if($request['num'] < 10){
// return '订单金额不能小于10元';
// }
// $request['proid'] = $this->getGid($param['cash']);
// $request['account'] = $param['account'];
//
//
//
// break;
// }
//
// }
$request['notify_url'] = $this->getNotify($param['order'], 1);
$request['sign'] = $this->_sign($request);
$url = $this->host . $this->api;
$response = $this->curl('post', $url, $request ,true);
$response = $this->response($response);
//$response['data'] = '{}';
//$response['msg'] = 'ok';
$channel_order_id = '';
if(isset($response['array']['data']['orderNo']) && !empty($response['array']['data']['orderNo'])) {
$channel_order_id = $response['array']['data']['orderNo'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
return $response['msg'];
}
public function _sign($request)
{
ksort($request);
if(isset($request['sign'])){
unset($request['sign']);
}
$signature_string = '';
foreach ($request as $k => $v) {
$signature_string .= $k . $v ;
}
$signature_string .=$this->token;
return md5($signature_string);
}
}