242 lines
7.4 KiB
PHP
242 lines
7.4 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 Shuju 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']) {
|
|||
|
# 错误信息
|
|||
|
$msg = $result['msg'] = $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';
|
|||
|
}
|
|||
|
// elseif (isset($array['status']) && $array['status'] == '101') {
|
|||
|
// # 疑似
|
|||
|
// $msg = 'ys';
|
|||
|
// } elseif (isset($array['status']) && $array['status'] == '122616') {
|
|||
|
// # 疑似
|
|||
|
// $msg = 'ys';
|
|||
|
// }
|
|||
|
else {
|
|||
|
# 错误
|
|||
|
$msg = isset($array['desc']) ? $array['desc'] : 'error';
|
|||
|
}
|
|||
|
|
|||
|
# 增加卡密日志
|
|||
|
$order = array();
|
|||
|
if ($this->order_id) {
|
|||
|
$order = OrderService::instance()->get($this->order_id);
|
|||
|
|
|||
|
if ($order && $order['card_id'] > 0) {
|
|||
|
if ($msg == 'ok') {
|
|||
|
CardService::instance()->log($order, 3, '渠道下单成功');
|
|||
|
} else {
|
|||
|
CardService::instance()->log($order, 4, '渠道下单失败');
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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'];
|
|||
|
|
|||
|
$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['mapping_id'];
|
|||
|
$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 = '';
|
|||
|
|
|||
|
$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;
|
|||
|
}
|
|||
|
}
|