初始化代码
This commit is contained in:
113
longbingcore/wxcore/WxPay.php
Normal file
113
longbingcore/wxcore/WxPay.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\wxcore;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
class WxPay{
|
||||
|
||||
static protected $uniacid;
|
||||
|
||||
public function __construct($uniacid)
|
||||
{
|
||||
self::$uniacid = $uniacid;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 获取支付信息
|
||||
*/
|
||||
public function payConfig (){
|
||||
$uniacid_id = self::$uniacid;
|
||||
|
||||
$pay = Db::name('longbing_card_config_pay')->where(['uniacid'=>$uniacid_id])->find();
|
||||
$config = Db::name( 'longbing_card_config')->where(['uniacid' => $uniacid_id])->find();
|
||||
if(empty($pay[ 'mch_id' ])||empty($pay[ 'pay_key' ])){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '未配置支付信息'
|
||||
];
|
||||
}
|
||||
$setting[ 'payment' ][ 'merchant_id' ] = $pay[ 'mch_id' ];
|
||||
$setting[ 'payment' ][ 'key' ] = $pay[ 'pay_key' ];
|
||||
$setting[ 'payment' ][ 'cert_path' ] = $pay[ 'cert_path' ];
|
||||
$setting[ 'payment' ][ 'key_path' ] = $pay[ 'key_path' ];
|
||||
$setting[ 'app_id' ] = $config['appid'];
|
||||
$setting[ 'secret' ] = $config['app_secret'];
|
||||
return $setting;
|
||||
}
|
||||
/**
|
||||
* @param string $uid
|
||||
* @param string $money
|
||||
* @功能说明:提现
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-03-24 14:52
|
||||
*/
|
||||
public function crteateMchPay($paymentApp,$openid,$money='')
|
||||
{
|
||||
|
||||
$money = $money*100;
|
||||
|
||||
$payid = substr(md5('longbing1'.time()),0,11);
|
||||
//没有配置支付信息
|
||||
if(empty($paymentApp['app_id'])||empty($paymentApp['payment']['merchant_id'])){
|
||||
|
||||
return $paymentApp;
|
||||
|
||||
}
|
||||
//没有openid
|
||||
if(empty($openid)){
|
||||
|
||||
return [
|
||||
|
||||
'result_code' => false,
|
||||
|
||||
'return_code' => false,
|
||||
|
||||
'err_code_des'=> '用户信息错误'
|
||||
];
|
||||
}
|
||||
|
||||
$setting['mini_appid'] = $paymentApp['app_id'];
|
||||
$setting['mini_appsecrept'] = $paymentApp['secret'];
|
||||
$setting['mini_mid'] = $paymentApp['payment']['merchant_id'];
|
||||
$setting['mini_apicode'] = $paymentApp['payment']['key'];
|
||||
$setting['apiclient_cert'] = $paymentApp['payment']['cert_path'];
|
||||
$setting['apiclient_cert_key'] = $paymentApp['payment']['key_path'];
|
||||
|
||||
|
||||
define('WX_APPID', $setting['mini_appid']);
|
||||
define('WX_MCHID', $setting['mini_mid']);
|
||||
define('WX_KEY', $setting['mini_apicode']);
|
||||
define('WX_APPSECRET', $setting['mini_appsecrept']);
|
||||
define('WX_SSLCERT_PATH', $setting['apiclient_cert']);
|
||||
define('WX_SSLKEY_PATH', $setting['apiclient_cert_key']);
|
||||
define('WX_CURL_PROXY_HOST', '0.0.0.0');
|
||||
define('WX_CURL_PROXY_PORT', 0);
|
||||
define('WX_REPORT_LEVENL', 0);
|
||||
|
||||
require_once PAY_PATH . "weixinpay/lib/WxPay.Api.php";
|
||||
require_once PAY_PATH . "weixinpay/example/WxPay.JsApiPay.php";
|
||||
require_once PAY_PATH . "weixinpay/lib/WxMchPay.php";
|
||||
$payClass=new \WxMchPay();
|
||||
|
||||
$res=$payClass->MchPayOrder($openid,$money,$payid);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user