master
ljl 2 years ago
parent a979a1e8b5
commit c578c4b80e

@ -13,6 +13,8 @@ use Org\SumaPay\Notify as FFNotify;
use Org\SumaPay\Log as FFLog;
use Org\QzlPay\Log as QzlLog;
use Org\QzlPay\Response as QzlResponse;
use Org\Kudian\Response as KDResponse;
use Org\Kudian\Log as KDLog;
/**
* 支付回调控制器
* @author 小纯洁
@ -930,7 +932,7 @@ class NotifyController extends BaseController
}
/**
* 酷点回调
* 丰付回调
*/
public function ff_callback() {
@ -1033,4 +1035,45 @@ class NotifyController extends BaseController
}
echo 'SUCCESS';
}
/**
* 酷点回调
*/
public function kd_callback() {
$params = file_get_contents('php://input');
KDLog::write('NOTIFY_INPUT:' . file_get_contents('php://input'));
$response = new KDResponse($params);
if (!$response->verify()) {
echo 'SIGN_VERIFY_FAIL';
return;
}
if ($response->getResult('status') != 100) {
echo 'SUCCESS';
return;
}
$orderInfo['trade_no'] = $response->getResult('transaction_id');
$orderInfo['out_trade_no'] = $response->getResult('out_trade_no');
$orderInfo['money'] = round($response->getResult('fee') / 100, 2);
$payWhere = substr($orderInfo['out_trade_no'], 0, 2);
switch ($payWhere) {
case 'SP':
$result = $this->set_spend($orderInfo);
break;
case 'PF':
$result = $this->set_deposit($orderInfo);
break;
case 'AG':
$result = $this->set_agent($orderInfo);
break;
default:
exit('accident order data');
break;
}
echo 'SUCCESS';
}
}

@ -16,6 +16,7 @@ use Sdk\Model\PayChannelInterntionModel;
use Sdk\Model\PayChannelIntentionModel;
use Org\SumaPay\Api as FFApi;
use Org\QzlPay\Api as QzlApi;
use Org\Kudian\Api as KDApi;
class PayH5Controller extends BaseController{
const ALI_PAY = 1;
@ -200,6 +201,33 @@ class PayH5Controller extends BaseController{
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} elseif ($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 11;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$this->add_deposit($request, 1);
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'ALIPAY', $body, get_client_ip());
if($response->isSuccess()) {
// 存入pay_url 继续支付
M("deposit", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $response->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);exit;
}
} elseif($pay_info['channel'] == 7) { // 丰付
$request['pay_way'] = 12;
@ -589,6 +617,43 @@ class PayH5Controller extends BaseController{
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$json_data['ret_msg']}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} elseif($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 11;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = 1;
$request['main_id'] = $main_id;
$ordercheck = M("spend","tab_")->where(array('pay_order_number'=>$request["pay_order_number"]))->find();
if ($ordercheck) {
$returl = U('Spend/notice',array('user_id'=>$ordercheck['user_id'],'game_id'=>$ordercheck['game_id'],'msg'=>'订单已经存在,请刷新充值页面重新下单!'));
echo json_encode(['code'=>0,'msg'=>'订单已经存在,请刷新充值页面重新下单!','wap'=>1]);
exit;
}
$this->add_spend($request,1);
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'ALIPAY', $body, get_client_ip());
if($response->isSuccess()){
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $response->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} elseif($pay_info['channel'] == 7) { // 丰付
@ -850,9 +915,6 @@ class PayH5Controller extends BaseController{
}
/**
*微信支付
* 增加
* ALTER TABLE `tab_deposit`
ADD COLUMN `pay_url` text NULL AFTER `check_sign`;
*/
public function platform_weixin_pay() {
if (!$this->userId) {
@ -975,6 +1037,24 @@ class PayH5Controller extends BaseController{
jsonOutput(0, "支付失败");
exit;
}
} elseif($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 21;
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'WXPAY', $body, get_client_ip());
if($response->isSuccess()){
$request['pay_url'] = $response->getResult('url');
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
$this->add_deposit($request, 1);
} else {
jsonOutput(0, "支付失败");
exit;
}
}elseif ($pay_info['channel'] == 7) { // 丰付
$request['pay_way'] = 22;
$body = "消费-".$request["pay_order_number"];
@ -1605,7 +1685,7 @@ class PayH5Controller extends BaseController{
}
}
//捕获异常
catch(Exception $e)
catch(\Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
@ -1639,10 +1719,6 @@ class PayH5Controller extends BaseController{
/**
*微信支付
*ALTER TABLE `tab_spend`
ADD COLUMN `pay_url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `old_promote_account`;
*/
public function weixin_pay($user_id,$game_id) {
@ -1779,6 +1855,43 @@ class PayH5Controller extends BaseController{
echo json_encode(['code'=>0,'msg'=> '支付失败,请重试'.$json_data['ret_msg']]);
exit;
}
} elseif($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 21;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = 2;
$request['main_id'] = $main_id;
$ordercheck = M("spend","tab_")->where(array('pay_order_number'=>$request["pay_order_number"]))->find();
if ($ordercheck) {
$returl = U('Spend/notice',array('user_id'=>$ordercheck['user_id'],'game_id'=>$ordercheck['game_id'],'msg'=>'订单已经存在,请刷新充值页面重新下单!'));
echo json_encode(['code'=>0,'msg'=>'订单已经存在,请刷新充值页面重新下单!','wap'=>1]);
exit;
}
$this->add_spend($request,1);
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'WXPAY', $body, get_client_ip());
if($response->isSuccess()){
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $response->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} elseif($pay_info['channel'] == 7) { // 丰付
$request['pay_way'] = 22;
$request['pay_status'] = 0;

@ -0,0 +1,35 @@
<?php
namespace Org\Kudian;
use Org\Kudian\Request\H5PayRequest;
use Org\Kudian\Request\Request;
class Api
{
private static $client;
private static function getClient() {
if (!self::$client) {
self::$client = new Client();
}
return self::$client;
}
public static function h5Pay($orderNumber, $amount, $notifyUrl, $backUrl, $payType, $body, $clientIp) {
$request = new H5payRequest(Config::get('mch_id'), Config::get('secret_key'));
$request->setContent([
'fee' => $amount,
'out_trade_no' => $orderNumber,
'body' => $body,
'client_ip' => $clientIp,
'notify_url' => $notifyUrl,
'payment' => $payType,
'sence_info' => [
'wap_url' => 'http://www.jianghuifa.cn',
'wap_name' => '聚游',
'return_url' => $backUrl,
],
]);
return self::getClient()->request($request);
}
}

@ -0,0 +1,47 @@
<?php
namespace Org\Kudian;
use Exception;
use Org\Kudian\Request\Request;
class Client
{
public function request(Request $request): Response
{
$response = '';
try {
$response = $this->post($request->getUrl(), $request->getParams());
Log::write('REQUEST_RESPONSE: ' . $response);
} catch (Exception $e) {
Log::write('REQUEST_ERROR: ' . $e->getMessage());
$response = json_encode([
'code' => -999,
'msg' => '网络错误',
'sign_type' => 'MD5',
'sign' => '',
'result' => json_encode([]),
]);
}
return new Response($response);
}
public function post($url, $params): string
{
Log::write('REQUEST_URL: ' . json_encode($url));
Log::write('REQUEST_DATA: ' . json_encode($params));
$curl = curl_init();
if (stripos($url, 'https://') !== false){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
$headers = ['Content-type: application/json'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}

@ -0,0 +1,16 @@
<?php
namespace Org\Kudian;
class Config
{
private static $params = [
'base_url' => 'https://pay.kudianvip.com',
'mch_id' => 'KP10009694',
'secret_key' => 'q5zZyyA071zS0SZR6xcz0gP0fFhtojqq',
];
public static function get($key, $default = null)
{
return self::$params[$key] ?? $default;
}
}

@ -0,0 +1,12 @@
<?php
namespace Org\Kudian;
use Think\Log as ThinkLog;
class Log
{
public static function write($message, $level = ThinkLog::INFO) {
$destination = C('LOG_PATH'). 'kudian/' . date('y_m_d').'.log';
ThinkLog::write($message, $level, '', $destination);
}
}

@ -0,0 +1,12 @@
<?php
namespace Org\Kudian\Request;
class H5PayRequest extends Request
{
protected $url = '/openapi/pay/kdh5pay';
public function setContent(array $content)
{
$this->content = $content;
}
}

@ -0,0 +1,64 @@
<?php
namespace Org\Kudian\Request;
use Org\Kudian\Config;
use Org\Kudian\Sign;
class Request
{
protected $url;
protected $mchId;
protected $timestamp;
protected $nonceStr;
protected $sign;
protected $signType;
protected $content;
protected $secretKey;
public function __construct($mchId, $secretKey)
{
$this->mchId = $mchId;
$this->secretKey = $secretKey;
$this->timestamp = time();
$this->nonceStr = self::generateRandomString();
$this->signType = 'MD5';
}
public function setContent(array $content)
{
$this->content = json_encode($content);
}
final public function reset()
{
$this->timestamp = time();
$this->nonceStr = self::generateRandomString();
}
final protected function generateRandomString($length = 16)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$string = '';
for ( $i = 0; $i < $length; $i++ )
$string .= $chars[mt_rand(0, strlen($chars) - 1)];
return $string;
}
public function getParams() {
$params = [
'mch_id' => $this->mchId,
'timestamp' => $this->timestamp,
'nonce_str' => $this->nonceStr,
'sign_type' => $this->signType,
'content' => json_encode($this->content, JSON_UNESCAPED_UNICODE),
];
$params[Sign::SIGN_KEY] = Sign::generate($params, $this->secretKey);
return $params;
}
public function getUrl() {
return Config::get('base_url') . $this->url;
}
}

@ -0,0 +1,88 @@
<?php
namespace Org\Kudian;
class Response
{
protected $code;
protected $msg;
protected $result;
protected $sign;
protected $signType;
protected $data;
public function __construct($response)
{
$this->parse($response);
}
private function parse($response)
{
$data = null;
if (is_array($response)) {
Log::write('RESPONSE_ARRAY: ' . json_encode($response));
$data = $response;
} else {
Log::write('RESPONSE_STR: ' . $response);
$data = json_decode($response, true);
}
if (!$data) {
$data = [
'code' => -998,
'msg' => '数据异常',
'sign' => '',
'sign_type' => 'MD5',
'result' => json_encode([]),
];
}
$this->data = $data;
$result = $data['result'] ? json_decode($data['result'], true) : [];
$this->result = $result;
$this->code = $data['code'];
$this->msg = $data['msg'];
$this->sign = $data['sign'];
$this->signType = $data['sign_type'];
}
public function isSuccess()
{
return !($this->code < 0);
}
public function getCode()
{
return $this->code;
}
public function getMsg()
{
return $this->msg;
}
public function getResult($key = null)
{
if ($key) {
return $this->result[$key] ?: null;
}
return $this->result;
}
public function getSign()
{
return $this->sign;
}
public function getSignType()
{
return $this->signType;
}
public function verify()
{
return Sign::verify($this->data, Config::get('secret_key'));
}
}

@ -0,0 +1,29 @@
<?php
namespace Org\Kudian;
class Sign
{
const SIGN_KEY = 'sign';
public static function generate($params, $secretKey)
{
Log::write('SIGN_PARAMS: ' . json_encode($params));
unset($params[self::SIGN_KEY]);
ksort($params);
$signStr = '';
foreach ($params as $key => $value) {
$signStr .= $key . "=" . $value . "&";
}
$signStr = rtrim($signStr, '&') . "&secret_key=" . $secretKey;
Log::write('SIGN_STR: ' . $signStr);
$sign = md5($signStr);
$sign = strtoupper($sign);
return $sign;
}
public static function verify($params, $secretKey)
{
$sign = $params[self::SIGN_KEY] ?: null;
return self::generate($params, $secretKey) == $sign;
}
}
Loading…
Cancel
Save