260 lines
7.9 KiB
PHP
260 lines
7.9 KiB
PHP
<?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 Shuju2 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
|
||
(
|
||
'card' => '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是失败
|
||
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;
|
||
}else {
|
||
$result['status'] = 4;
|
||
}
|
||
if (isset($data['szRtnMsg']) && $data['szRtnMsg']) {
|
||
# 流水号
|
||
$data['s_nubmer'] = $result['s_nubmer'] = $data['szRtnMsg'];
|
||
}
|
||
|
||
$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 = $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 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 query($param)
|
||
{
|
||
|
||
}
|
||
|
||
# 提交数据
|
||
private function submit($param, $check)
|
||
{
|
||
|
||
$param = $this->param($param, $check);
|
||
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||
return $param;
|
||
}
|
||
|
||
#TODO 以下修改
|
||
// $getphoneinfo = $this->getMobileInfo($param['account']);#此处为获取省份,运营商;
|
||
// $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'].'元';
|
||
// var_dump($mappingname);exit;
|
||
// $productInfo = array(
|
||
//// 'mapping_id' =>
|
||
// );
|
||
// $productInfo= ProductMappingService::instance()->getMapping($mappingname,2,'mapping_id');#2=cid,$mappingname为名字,mappingid直接返回映射id
|
||
|
||
|
||
|
||
// var_dump($request['szProductId']);exit;
|
||
#TODO 结束
|
||
$request = $param['detail'];
|
||
$productInfo = $this->getMapping($request['nSortType'],$request['nMoney']);#2=cid,$mappingname为名字,mappingid直接返回映射id
|
||
|
||
$request['szAgentId'] = $this->mid;
|
||
$request['szOrderId'] = $param['order'];
|
||
// $request['szPhoneNum'] = $param['account'];
|
||
// $request['nMoney'] = $param['cash'];
|
||
// $request['nSortType'] = $this->lprefix;
|
||
$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);
|
||
$request['szNotifyUrl'] = $this->getNotify($param['order'], 1);
|
||
$request['szProductId'] = $productInfo;
|
||
$url = $this->host . $this->api;
|
||
// $response = $this->curl('post', $url, $request,false,'Content-Type:application/x-www-form-urlencoded');
|
||
$response = $this->send_post($url,$request,'POST');
|
||
$response = $this->response($response);
|
||
//$response['data'] = '';
|
||
//$response['msg'] = 'ok';
|
||
$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='')
|
||
{
|
||
|
||
// $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);
|
||
}
|
||
|
||
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 getMapping($param,$cash)
|
||
{
|
||
if($param == '3'){
|
||
if($cash == '50'){
|
||
return '3000050';
|
||
} elseif($cash == '100'){
|
||
return '3000100';
|
||
}elseif($cash == '200') {
|
||
return '3000200';
|
||
}
|
||
}elseif($param == '1'){
|
||
if($cash == '50'){
|
||
return '1000050';
|
||
}elseif($cash == '100'){
|
||
return '1000100';
|
||
}elseif($cash == '200') {
|
||
return '1000200';
|
||
}
|
||
}elseif($param == '2') {
|
||
if ($cash == '50') {
|
||
return '2000050';
|
||
} elseif ($cash == '100') {
|
||
return '2000100';
|
||
} elseif ($cash == '200') {
|
||
return '2000200';
|
||
}
|
||
}
|
||
|
||
}
|
||
} |