master
elf 2 years ago
parent e1c57150bd
commit b47336085f

@ -9,7 +9,9 @@ use Think\Log;
use Qiniu\json_decode;
use Sdk\Controller\Ipa365Controller;
use Base\Tool\Redis;
use Org\Kudian\Config as KDConfig;
use Org\Kudian\Sign as KDSign;
use Org\Kudian\Response as KDResponse;
/**
* 支付回调控制器
@ -927,4 +929,43 @@ class NotifyController extends BaseController
echo "SUCCESS";
}
/**
* 酷点回调
*/
public function kd_callback() {
$params = I('post.');
Log::write(serialize($params), Log::DEBUG);
$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';
}
}

@ -14,6 +14,7 @@ use Sdk\Model\ValueDetailLogModel;
use Sdk\Model\PayLimitConfModel;
use Sdk\Model\PayChannelInterntionModel;
use Sdk\Model\PayChannelIntentionModel;
use Org\Kudian\Api as KDApi;
class PayH5Controller extends BaseController{
@ -519,6 +520,44 @@ 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();
$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, 'ALI_PAY', $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'=> "请求发起失败【{$request->getMsg()}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} else{ // 支付宝第三方
if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){
// $this->set_message(1009, "fail", "支付参数未配置");
@ -816,6 +855,44 @@ class PayH5Controller extends BaseController{
jsonOutput(0, "支付失败");
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'] = 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, 'WX_PAY', $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(get_wx_pay_type() == 2){
if($request['code']==1){

@ -0,0 +1,35 @@
<?php
namespace Org\Kudian;
use Org\Kudian\Request\H5payRequest;
use Org\Kudian\Request\Request;
class Api
{
private $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,43 @@
<?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());
} catch (Exception $e) {
$response = json_encode([
'code' => -999,
'msg' => '网络错误',
'sign_type' => 'MD5',
'sign' => '',
'result' => json_encode([]),
]);
}
return new Response($response);
}
public function post($url, $params): string
{
$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;charset=utf-8'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}

@ -0,0 +1,15 @@
<?php
namespace Org\Kudian;
class Config
{
private static $params = [
'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\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' => $this->content,
];
$params[Sign::SIGN_KEY] = Sign::generate($params, $this->secretKey);
return $params;
}
public function getUrl() {
return $this->url;
}
}

@ -0,0 +1,86 @@
<?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)) {
$data = $response;
} else {
$data = json_decode($response);
}
if (!$data) {
$data = [
'code' => -998,
'msg' => '数据异常',
'sign' => '',
'sign_type' => 'MD5',
'result' => json_encode([]),
];
}
$this->data = $data;
$result = $data['result'] ? json_decode($data['result']) : [];
$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,27 @@
<?php
namespace Org\Kudian;
class Sign
{
const SIGN_KEY = 'sign';
public static function generate($params, $secretKey)
{
unset($params[self::SIGN_KEY]);
ksort($params);
$signStr = '';
foreach ($params as $key => $value) {
$signStr .= $key . "=" . $value . "&";
}
$signStr = rtrim($signStr, '&') . "&secret_key=" . $secretKey;
$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