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

290 lines
8.4 KiB
PHP
Raw 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\CardService;
use app\merchant\service\OrderService;
use app\channel\service\ProductMappingService;
/**
* 年年服务
* Class Bodingcheng
* @package app\channel\service
*/
class NianNian extends Core
{
# 这几个可以后台设置
protected $host = '';
protected $mid = '';
protected $token = '';
protected $card = array();
protected $order_id = '';
protected $api = '';
protected $sign = array();
protected $lprefix = '';
# 电话充值
public function dhcz($param)
{
$check = array
(
'mobile' => 'szPhoneNum',
'cash' => 'nMoney',
'nSortType'=>'nSortType',
);
$param['nSortType'] = '1';
if (isset($param['isp']) && $param['isp']) {
$param['nSortType']= $param['isp'];
}
$param['nProductClass']=1;
$param['nProductType']=1;
$this->sign = array('szAgentId', 'szOrderId', 'szPhoneNum', 'nMoney', 'nSortType', 'nProductClass','nProductType','szProductId','szTimeStamp');
$this->api = 'api/submitorder';
return $this->submit($param, $check);
}
# 通知处理 主要返回状态 2是成功 3是失败
private function submit($param, $check)
{
$param = $this->param($param, $check);
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
return $param;
}
$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'].$getPhoneInfo['sp'].$param['cash'].'元';
$productInfo = ProductMappingService::instance()->getMapping($mappingName,2,'mapping_id');#2=cid$mappingname为名字,mappingid直接返回映射id
$request = $param['detail'];
$request['szAgentId'] = $this->mid;
$request['szOrderId'] = $param['order'];
$request['nProductClass'] = 1;
$request['nProductType'] = 1;
// $request['szProductId'] = $this->getGid($param['cash']);
$request['szTimeStamp'] = date("Y-m-d H:i:s",time());
ksort($request);
$request['szVerifyString'] = $this->_sign($request, $this->sign);
$request['szNotifyUrl'] = $this->getNotify($param['order'], 1);
$request['szProductId'] = $productInfo['mapping_id'];
$url = $this->host . $this->api;
$response = $this->send_post($url,$request,'POST');
$response = $this->response($response);
$channel_order_id = '';
if (isset($response['array']['szRtnCode']) && $response['array']['szRtnCode'] != 'success') {
#警告类型
$channel_order_id = $response['array']['szRtnCode'];
}
// $channel_order_id = '';
$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]) && $request[$v]) {
$signature_string .= $v . '=' . $request[$v] . '&';
}
$signature_string = substr($signature_string, 0, -1);
$signature_string .= '&szKey='.$this->token;
// var_dump($signature_string);die;
// $signature_string = iconv("UTF-8", "gbk", $signature_string);
return md5($signature_string);
}
# 订单查询
public function send_post($notify_url, $post_data,$type)
{
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => $type,
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s
)
);
$context = stream_context_create($options);
$result = file_get_contents($notify_url, false, $context);
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['nRtn']) && $array['nRtn'] == '0') {
# 正确
$msg = 'ok';
}
// }
else {
# 错误
$msg = $array['desc'] ?? 'error';
}
return array
(
'msg' => $msg,
'data' => $data,
'array' => $array,
);
}
# 查询余额接口
public function notify($data)
{
$request = $data;
$result = array();
$result['cash'] = 1;
$result['status'] = 4;
if ($data['nFlag'] == 2) {
$result['status'] = 2;
} else if($data['nFlag'] == 3) {
$result['status'] = 3;
}
if (isset($data['szRtnMsg']) && $data['szRtnMsg']) {
# 流水号
$data['s_nubmer'] = $result['s_nubmer'] = $data['szRtnMsg'];
}
$result['yes'] = 'OK';
$result['data'] = $data;
return $result;
}
# 查询接口
public function ddcx($param)
{
$check = array
(
'order_id' => 'szOrderId',
);
$this->sign = array('szAgentId', 'szOrderId');
$this->api = 'api/old/queryorder';
return $this->submit($param, $check);
}
# 提交数据
public function balance($param)
{
$check = array
(
);
$this->sign = array('szAgentId');
$this->api = 'api/old/queryBalance';
return $this->submit($param, $check);
}
public function account($day)
{
$request['day'] = $day;
$request['szAgentId'] = $this->mid;
$request['api_product'] = 'query';
$this->token = $this->mid . '|' . $this->token;
$request = $this->getParam($request, $this->token);
$url = $this->host . 'api/old/queryBalance';
$response = $this->curl('post', $url, $request);
$response = $this->response($response);
return $response['array']['data'];
}
public function query($order)
{
// $orderRequest = json_decode($order['request'], true);
$request['szAgentId'] = $this->mid;
$request['szOrderId'] = $order;
$request['szVerifyString'] = $this->_sign($request, array('szAgentId', 'szOrderId'));
$request['szFormat'] = 'json';
$url = $this->host . 'api/old/queryorder';
$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['nRtn']) ) {
if($array['nRtn'] == '5012'){
$result['status'] = 2;
}elseif ($array['nRtn'] == '5013'){
$result['status'] = 3;
}
if (isset($array['szRtnMsg']) && $array['szRtnMsg']) {
# 流水号
$result['s_nubmer'] = $array['szRtnMsg'];
}
}
return $result;
}
private function _sign1($request, $param='')
{
// $signature_string = '';
//
// foreach ($request as $k => $v) {
// if (isset($request[$k]) && $request[$k]) {
// $signature_string .= $k . '=' . $request[$k] . '&';
// }
// }
$signature_string='szAgentId='.$request['szAgentId'].'&szOrderId='.$request['szOrderId'].'&szPhoneNum='.$request['szPhoneNum'].'&nMoney='.$request['nMoney'].'&nSortType='.$request['nSortType'].'&nProductClass='.$request['nProductClass'].'&nProductType='
.$request['nProductType'].'&szTimeStamp='.$request['szTimeStamp'].'&szKey='.$this->token;
// $signature_string .='szKey='. $this->token;
// var_dump($signature_string);exit;
return md5($signature_string);
}
}