mzeros b8c34de8c8 refactor(merchant): 优化账户数据处理和订单逻辑
- 添加 endsWithDoubleZero 函数,用于处理数值字符串末尾的两个零
- 修改 Core.php 中的 queue 方法,增加对卡库提单的特殊处理逻辑
-调整 Feedov.php 中的订单查询和充值逻辑,提高系统稳定性
- 优化数据库配置,连接测试数据库以确保数据安全
2025-02-15 19:00:17 +08:00

430 lines
12 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\channel\service\system;
use app\channel\service\ProductMappingService;
/**
* 久久福服务
* Class Jiujiufu
* @package app\channel\service
*/
class Jiujiufu extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $method = '';
protected $appsecret='';
protected $Operator = '';
protected $sp = '';
# 电话充值 拼音来吧
public function dhcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$param['api_product'] = 'dhcz';
return $this->submit($param, $check);
}
public function ltcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$this->sp = '联通';
$param['api_product'] = 'ltcz';
return $this->submit($param, $check);
}
public function dxcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$this->sp = '电信';
$param['api_product'] = 'dxcz';
return $this->submit($param, $check);
}
public function ydcz($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$this->sp = '移动';
$param['api_product'] = 'ydcz';
return $this->submit($param, $check);
}
public function ydcz_alipay($param)
{
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$this->sp = '移动';
$param['api_product'] = 'ydcz';
return $this->submit($param, $check);
}
# 中石油油卡充值 拼音来吧
public function zsycz($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
'idCard' => 'idCard',
'realName' => 'realName',
'api_product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$param['api_product'] = 'zsycz';
return $this->submit($param, $check);
}
# 中石化油卡充值
public function zshcz($param)
{
$check = array
(
'card' => 'card',
'cash' => 'cash',
'api_product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$param['api_product'] = 'zshcz';
return $this->submit($param, $check);
}
public function zshcz_wt($param){
$check = array
(
'mobile' => 'mobile',
'cash' => 'cash',
'VerificationCode' => 'code',
'api_product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$param['api_product'] = 'zshcz';
return $this->submit($param, $check);
}
#抖音币充值
public function dy($param){
$check = array
(
'account' => 'account',
'cash' => 'cash',
'api_product' => 'api_product',
);
if(isset($param['api_product'])){
unset($check['product']);
$check['api_product'] = 'api_product';
}
$param['api_product'] = 'dbcz';
$param['cash'] = $param['cash'] * $param['num']??1;
return $this->submit($param, $check);
}
#获取手机号码
public function getMobileCode($param)
{
$request = [];
$request['appid'] = $this->mid;
$request['api_product'] = 'zshcz';
$request['cash'] = 1;
$request['mobile'] = $param['mobile'];
$request = $this->getParam($request, $this->token, 1);
$url = $this->host . 'gateway/api.handle/code';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
return $response['msg'];
}
# 通知处理 主要返回状态 2是成功 3是失败
public function notify($data)
{
$request = $data;
unset($request['signature']);
// $request = $this->getParam($request, $this->token, 2);
// if ($request['signature'] != $data['signature']) {
// return false;
// }
$result = array();
$result['cash'] = 1;
if ($data['status'] == 2) {
$result['status'] = 2;
} elseif ($data['status'] == 3) {
$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['number']) && $data['number']) {
# 流水号
$data['s_number'] = $result['s_number'] = $data['number'];
}
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'] == 1) {
# 正确
$msg = 'ok';
} else {
# 错误
$msg = isset($array['info']) ? $array['info'] : 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询接口
public function query($order)
{
$time=time();
$request=array(
'appid'=>$this->mid,
'api_product'=>'query',
// 'order_id'=>$order->order_id,
'merchant_order_id'=>$order->order_id,
'nonce'=>$time.rand(0,9),
'time'=>$time,
);
$request['signature']=$this->_sign($request);
#
$url = $this->host . 'gateway/api.handle/order';
$response = $this->curl('post', $url, $request);
$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['day'] = $day;
$request['appid'] = $this->mid;
$request['api_product'] = 'query';
$request = $this->getParam($request, $this->token);
// $url = $this->host . 'gateway/api.handle/accountByDay';
$url = $this->host . 'gateway/api.handle/account';
$response = $this->curl('post', $url, $request);
// var_dump($response);die;
$response = $this->response($response);
return $response['array']['data'];
}
# 提交数据
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
return $this->send($param);
}
#签名
private function _sign($param)
{
$token=strtolower(sha1($this->mid.'|'.$this->appsecret));
$param['token']=$token;
return strtolower(sha1($this->to_str($param)));
}
public function to_str($data){
ksort($data);
$signature_string = '';
foreach ($data as $k => $v) {
if (strlen($v)) {
$signature_string .= $k . '=' . $v . '&';
}
}
$signature_string = substr($signature_string, 0, -1);
return $signature_string;
}
private function send($param, $parent_order = '')
{
$request = $param['detail'];
$request['appid'] = $this->mid;
$request['order'] = $param['order'];
if(isset($request['api_product']) && $request['api_product'] == 'ltcz' || $request['api_product'] == 'dxcz'|| $request['api_product'] == 'ydcz' ){
$getphoneinfo = \app\core\Service::instance()->ispguishudi($param['account']);
if($getphoneinfo == 1){
$getphoneinfo = $this->getMobileInfo($param['account']);
}
$getphoneinfo['province'] = str_replace('省','', $getphoneinfo['province']);
$mappingname = $getphoneinfo['province'].$this->sp.$param['cash'].'元';
$productInfo = ProductMappingService::instance()->getMapping($mappingname,$this->channel['id'],'mapping_id');#2=cid$mappingname为名字
if(!$productInfo){
$Gid = $this->getGid($param['cash']);
if(isset($Gid) && !empty($Gid) && $Gid != 'dhcz'){
unset($request['api_product']);
unset($request['cash']);
$request['proid'] = $Gid;
$request['account'] = $request['mobile'];
// unset($request['mobile']);
}else{
$request['api_product'] = 'dhcz';
}
}else{
unset($request['api_product']);
unset($request['cash']);
$request['proid'] = $productInfo['mapping_id'];
$request['account'] = $request['mobile'];
unset($request['mobile']);
}
}
$request['notify'] = $this->getNotify($param['order'], 1);
$request = $this->getParam($request, $this->token, 1);
$url = $this->host . 'gateway/api.handle/submit';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
//$response['data'] = '{}';
//$response['msg'] = 'ok';
$channel_order_id = '';
if(isset($response['array']['data']['order']) && $response['array']['data']['order']){
$channel_order_id = $response['array']['data']['order'];
}
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account'], $parent_order);
return $response['msg'];
}
}