355 lines
10 KiB
PHP
355 lines
10 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
namespace app\channel\service\system;
|
|||
|
use app\merchant\service\MerchantService;
|
|||
|
use app\merchant\service\OrderService;
|
|||
|
|
|||
|
/**
|
|||
|
* 骏网接口
|
|||
|
* Class Junka
|
|||
|
* @package app\channel\service
|
|||
|
*/
|
|||
|
class Youxin extends Core
|
|||
|
{
|
|||
|
# 这几个可以后台设置
|
|||
|
protected $host = 'http://user.youxinnet.cn/';
|
|||
|
protected $mid = 'dongfakeji';
|
|||
|
protected $token = 'dfkj6688';
|
|||
|
protected $api = '';
|
|||
|
|
|||
|
protected $aeskey = '383147446d6e4e6c';
|
|||
|
protected $goodid = '';
|
|||
|
|
|||
|
# 沃尔玛卡卡密
|
|||
|
public function walmart_cardbuy($param)
|
|||
|
{
|
|||
|
$check = array
|
|||
|
(
|
|||
|
// 'proid' => 'productCode',
|
|||
|
'num' => 'BuyNum',
|
|||
|
'ChargeAccount'=>'ChargeAccount'
|
|||
|
|
|||
|
);
|
|||
|
$param['ChargeAccount'] = 'kami';#新魔力卡种
|
|||
|
|
|||
|
$this->api = 'api/Order/CreateFlowOrder';
|
|||
|
return $this->submit($param, $check);
|
|||
|
// var_dump($param);die;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
# 沃尔玛卡卡密
|
|||
|
|
|||
|
|
|||
|
public function jkzx_cardbuy($param)
|
|||
|
{
|
|||
|
$check = array
|
|||
|
(
|
|||
|
// 'proid' => 'productCode',
|
|||
|
'num' => 'BuyNum',
|
|||
|
'ChargeAccount'=>'ChargeAccount'
|
|||
|
|
|||
|
);
|
|||
|
$param['ChargeAccount'] = 'kami';#新魔力卡种
|
|||
|
|
|||
|
$this->api = 'api/Order/CreateFlowOrder';
|
|||
|
return $this->submit($param, $check);
|
|||
|
// var_dump($param);die;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
# Q币充值
|
|||
|
public function qbcz($param)
|
|||
|
{
|
|||
|
$check = array
|
|||
|
(
|
|||
|
'num' => 'BuyNum',
|
|||
|
'account' => 'ChargeAccount',
|
|||
|
);
|
|||
|
$this->api = 'api/Order/CreateFlowOrder';
|
|||
|
return $this->submit($param, $check);
|
|||
|
}
|
|||
|
|
|||
|
#抖币
|
|||
|
public function dy($param)
|
|||
|
{
|
|||
|
$check = array
|
|||
|
(
|
|||
|
'num' => 'BuyNum',
|
|||
|
'account' => 'ChargeAccount',
|
|||
|
);
|
|||
|
$this->api = 'api/Order/CreateFlowOrder';
|
|||
|
return $this->submit($param, $check);
|
|||
|
}
|
|||
|
|
|||
|
#快手币
|
|||
|
public function ks($param)
|
|||
|
{
|
|||
|
$check = array
|
|||
|
(
|
|||
|
'num' => 'BuyNum',
|
|||
|
'account' => 'ChargeAccount',
|
|||
|
);
|
|||
|
$this->api = 'api/Order/CreateFlowOrder';
|
|||
|
return $this->submit($param, $check);
|
|||
|
}
|
|||
|
|
|||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
|||
|
public function notify($data)
|
|||
|
{
|
|||
|
$request = $data;
|
|||
|
$result = array();
|
|||
|
$result['cash'] = 1;
|
|||
|
// $result['status'] = 4;
|
|||
|
if ($data['Status'] == 1) {
|
|||
|
$result['status'] = 2;
|
|||
|
} else if($data['Status'] == 2) {
|
|||
|
$result['status'] = 3;
|
|||
|
}else {
|
|||
|
$result['status'] = 4;
|
|||
|
}
|
|||
|
if (isset($data['StatusMsg']) && $data['StatusMsg']) {
|
|||
|
# 流水号
|
|||
|
$data['s_nubmer'] = $result['s_nubmer'] = $data['StatusMsg'];
|
|||
|
}
|
|||
|
|
|||
|
$result['yes'] = 'OK';
|
|||
|
|
|||
|
$result['data'] = $data;
|
|||
|
|
|||
|
return $result;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public function cardbuy($param)
|
|||
|
{
|
|||
|
// var_dump($param);die;
|
|||
|
$check = array
|
|||
|
(
|
|||
|
// 'proid' => 'productCode',
|
|||
|
'num' => 'product_num',
|
|||
|
|
|||
|
);
|
|||
|
|
|||
|
$this->api = 'UCard/UCardFetchSubmit.aspx';
|
|||
|
return $this->submit($param, $check);
|
|||
|
}
|
|||
|
|
|||
|
# 数据响应格式处理
|
|||
|
public function response($data)
|
|||
|
{
|
|||
|
$log['type'] = 'response';
|
|||
|
$log['data'] = $data;
|
|||
|
$log['config'] = $this->data;
|
|||
|
$this->log($log);
|
|||
|
|
|||
|
// {"Code":1,"Content":{"SaleMoney":10.2200,"GoodsId":2811,"OrderTime":"2024-04-16 10:14:37.000","GoodsName":"腾讯全国Q币1元","OrderId":"13006856310501376"},"Message":"响应成功"}
|
|||
|
|
|||
|
$array = $this->json_decode($data);
|
|||
|
|
|||
|
if (!$array) {
|
|||
|
$msg = 'error';
|
|||
|
} elseif (isset($array['Code']) && $array['Code'] == '1') {
|
|||
|
# 正确
|
|||
|
$msg = 'ok';
|
|||
|
} else {
|
|||
|
# 错误
|
|||
|
$msg = isset($array['Message']) ? $array['Message'] : 'error';
|
|||
|
}
|
|||
|
|
|||
|
return array
|
|||
|
(
|
|||
|
'msg' => $msg,
|
|||
|
'data' => $data,
|
|||
|
'array' => $array,
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
# 查询接口
|
|||
|
public function query($order)
|
|||
|
{
|
|||
|
$orderRequest = json_decode($order['request'], true);
|
|||
|
$request['UserId'] = $this->mid;
|
|||
|
$request['UserOrderId'] = $order['order_id'];
|
|||
|
$request['TimeStamp'] =date('YmdHis');
|
|||
|
#timestamp{$时间戳A}userid20817userorderid{$订单编号}key09261cb9068b9cd7c4ece6f468d955eb
|
|||
|
|
|||
|
$request['Sign'] = $this->_sign($request, array('TimeStamp', 'UserId', 'UserOrderId'));
|
|||
|
$url = $this->host . 'api/Order/QueryChargeCardsResult';
|
|||
|
$response = $this->send_post($url,$request,'POST' );
|
|||
|
|
|||
|
$log['type'] = 'query_response';
|
|||
|
$log['data'] = $response;
|
|||
|
$log['config'] = $this->data;
|
|||
|
$this->log($log);
|
|||
|
$array = $this->json_decode($response);
|
|||
|
#{"Code":1,"Content":{"Cards":[],"SaleMoney":"10.2200","StatusMsg":"成功","Status":"1","UserOrderId":"3851936066457190837","OrderId":"13006988870623232"},"Message":"响应成功"}
|
|||
|
|
|||
|
$result['Status'] = 4;
|
|||
|
if (isset($array['Code']) ) {
|
|||
|
if($array['Status'] == '1'){
|
|||
|
$result['nFlag'] = 2;
|
|||
|
$result['status'] = 2;
|
|||
|
}elseif ($array['nRtn'] == '5013'){
|
|||
|
$result['nFlag'] = 3;
|
|||
|
$result['status'] = 3;
|
|||
|
}
|
|||
|
if (isset($array['szRtnMsg']) && $array['szRtnMsg']) {
|
|||
|
# 流水号
|
|||
|
// $data['szRtnMsg']
|
|||
|
$result['szRtnMsg'] = $array['szRtnMsg'];
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
return $result;
|
|||
|
|
|||
|
|
|||
|
// $pairs = explode('&', $response);
|
|||
|
// $array = [];
|
|||
|
// foreach ($pairs as $pair) {
|
|||
|
// // 分割键和值
|
|||
|
// list($key, $value) = explode('=', $pair);
|
|||
|
// // 解码键和值
|
|||
|
// $array[urldecode($key)] = urldecode($value);
|
|||
|
// }
|
|||
|
//
|
|||
|
//
|
|||
|
//
|
|||
|
// $result = array();
|
|||
|
//// $result['status'] = 4;
|
|||
|
// if (isset($array['ret_code']) && $array['ret_code'] == '0') {
|
|||
|
// if(isset($array['card_no_data'])){
|
|||
|
// $kami = $this->decrypt_3des($array['card_no_data']);
|
|||
|
// $kami = explode(',', $kami);
|
|||
|
// $kamidata = [
|
|||
|
// 'cardno' => $kami[0],
|
|||
|
// 'cardpwd' => $kami[1],
|
|||
|
// 'expired' => $kami[2],
|
|||
|
//
|
|||
|
// ];
|
|||
|
//
|
|||
|
// $this->upOrderResponse($kamidata,$order['merchant_order_id'],$order['response']);
|
|||
|
// $result['status'] = 7;
|
|||
|
// $result['kami'] = $kamidata;
|
|||
|
// }else{
|
|||
|
// $result['status'] = 4;
|
|||
|
// }
|
|||
|
//
|
|||
|
// } else{
|
|||
|
// $result['status'] = 3;
|
|||
|
// }
|
|||
|
//
|
|||
|
// if (isset($array['jnet_bill_no']) && $array['jnet_bill_no']) {
|
|||
|
// # 流水号
|
|||
|
//// $result['status'] = 3;
|
|||
|
// //$data['s_nubmer'] = $result['s_nubmer'] = $data['result']['code'];
|
|||
|
// }
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// return $result;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
# 提交数据
|
|||
|
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['UserId'] = $this->mid;
|
|||
|
$request['UserOrderId'] = $param['order'];
|
|||
|
// $request['bill_time'] = date('YmdHis');
|
|||
|
// $request['bill_id'] = $param['order'];
|
|||
|
$request['BuyNum'] = $request['BuyNum'] *$param['cash'];
|
|||
|
$request['GoodsId'] = $this->getGid($param['cash']);
|
|||
|
// $request['time_stamp'] = date('YmdHis');
|
|||
|
|
|||
|
$request['Sign'] = $this->_sign($request, array('BuyNum', 'ChargeAccount', 'GoodsId', 'UserId', 'UserOrderId'));
|
|||
|
$url = $this->host . $this->api;
|
|||
|
$response = $this->send_post($url,$request,'POST' );
|
|||
|
$response = $this->response($response);
|
|||
|
//$response['data'] = '';
|
|||
|
//$response['msg'] = 'ok';
|
|||
|
$channel_order_id = '';
|
|||
|
if (isset($response['array']['Content']['OrderId'])) {
|
|||
|
$channel_order_id = $response['array']['Content']['OrderId'];
|
|||
|
}
|
|||
|
|
|||
|
$param['account'] = $request['ChargeAccount'];
|
|||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
|||
|
return $response['msg'];
|
|||
|
}
|
|||
|
|
|||
|
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 decrypt_3des($encrypted_string){
|
|||
|
|
|||
|
$cipher = "des-ede3"; // 3des-ebc 使用的是des-ede3算法
|
|||
|
$mode = "ebc"; // 工作模式为ebc
|
|||
|
|
|||
|
$iv = ""; // EBC模式不需要IV,留空即可
|
|||
|
|
|||
|
return openssl_decrypt(hex2bin($encrypted_string), $cipher, $this->aeskey, $options=OPENSSL_RAW_DATA, $iv); // 输出解密后的字符串
|
|||
|
}
|
|||
|
|
|||
|
private function _sign($request, $param)
|
|||
|
{
|
|||
|
//ksort($request);
|
|||
|
$signature_string = '';
|
|||
|
foreach ($param as $k => $v) {
|
|||
|
// if (isset($request[$v]) && $request[$v]) {
|
|||
|
// var_dump($v);die;
|
|||
|
|
|||
|
$signature_string .= strtolower($v) . $request[$v] ;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// $signature_string = strtolower($signature_string);
|
|||
|
|
|||
|
$signature_string .= 'key'.$this->token;
|
|||
|
// var_dump($signature_string);die;
|
|||
|
$signature_string = iconv("UTF-8", "GBK", $signature_string);
|
|||
|
|
|||
|
// var_dump($signature_string);die;
|
|||
|
// $signature_string = iconv("UTF-8", "gbk", $signature_string);
|
|||
|
|
|||
|
return md5($signature_string);
|
|||
|
}
|
|||
|
public function upOrderResponse($kami,$merchant_order_id,$orderResponse)
|
|||
|
{
|
|||
|
$orderService = OrderService::instance();
|
|||
|
|
|||
|
$response = json_decode($orderResponse,true);
|
|||
|
$response['kami'] = $kami;
|
|||
|
$data = ['response' => json_encode($response)];
|
|||
|
|
|||
|
$orderService->db()->where(array('merchant_order_id' => $merchant_order_id))->update($data);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|