Commit b0661d3d authored by twj's avatar twj

同步服务器代码

parent 471c0a7e
......@@ -4,6 +4,7 @@ namespace app\admin\controller\users;
use app\common\controller\Backend;
use app\admin\controller\auth\Admin;
use app\admin\model\device\Chargedevice;
use think\Db;
use think\Exception;
......@@ -64,6 +65,9 @@ class Agent extends Backend
->where($where)
->order($sort, $order)
->paginate($limit);
foreach($list as $k=>$v){
$list[$k]['deviceCount']=Chargedevice::where(['user_id'=>$v['agent_user_id']])->count('1');
}
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
......
......@@ -210,7 +210,7 @@ class Withdraw extends Backend
$bankcard = $this->Bankcardmodel->where(['id' =>$val['bankcard_id']])->find();
switch ($val['withdraw_way']){
case 1://提现至零钱
$result = $wxpayConstants->crteateMchPayV2($usersinfo['wx_openid'], $desc, $val['cash_sn'], $val['money'], $val['name'], $jsonMap);
$result = $wxpayConstants->transfer($usersinfo['wx_openid'], $desc, $val['cash_sn'], $val['money'], $val['name'], $jsonMap);
break;
case 2://提现至银行卡
if($withraw_money <= 1000*100){
......
......@@ -253,34 +253,69 @@ class Createorder extends Api
if ($siteList) {
//遍历所有设备写入订单数据
foreach ($siteList as $k => $v) {
if ($v['profit_rank'] == 1) {
//生成的充电订单数
$chargeOrderNum = 10;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 12;
} elseif ($v['profit_rank'] == 2) {
//生成的充电订单数
$chargeOrderNum = 12;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 15;
} elseif ($v['profit_rank'] == 3) {
//生成的充电订单数
$chargeOrderNum = 15;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 15;
} elseif ($v['profit_rank'] == 4) {
//生成的充电订单数
$chargeOrderNum = 11;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 13;
//分为两个周期,第一个周期,第一年,每月平均2600左右,第二个周期,第二年后,每月平均1300左右
$secondYear = strtotime("+1 year", $v['authorizetime']);
$fourYear = strtotime("+5 year", $v['authorizetime']);
if (time() <= $secondYear) {
if ($v['profit_rank'] == 1) {
//生成的充电订单数
$chargeOrderNum = 10;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 12;
} elseif ($v['profit_rank'] == 2) {
//生成的充电订单数
$chargeOrderNum = 12;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 15;
} elseif ($v['profit_rank'] == 3) {
//生成的充电订单数
$chargeOrderNum = 15;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 15;
} elseif ($v['profit_rank'] == 4) {
//生成的充电订单数
$chargeOrderNum = 11;
//生成的包月订单数
$chargeCardOrderNum = 2;
//生成的广告订单数
$chargeAdOrderNum = 13;
}
}else{
if ($v['profit_rank'] == 1) {
//生成的充电订单数
$chargeOrderNum = 5;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 6;
} elseif ($v['profit_rank'] == 2) {
//生成的充电订单数
$chargeOrderNum = 6;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 8;
} elseif ($v['profit_rank'] == 3) {
//生成的充电订单数
$chargeOrderNum = 8;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 8;
} elseif ($v['profit_rank'] == 4) {
//生成的充电订单数
$chargeOrderNum = 6;
//生成的包月订单数
$chargeCardOrderNum = 1;
//生成的广告订单数
$chargeAdOrderNum = 7;
}
}
//是否需要生成订单标记
$addOrderFlag = 0;
......
<?php
/**
* Created by PhpStorm.
* User: Administrator
......@@ -7,22 +8,25 @@
*/
namespace app\lib\utils\WXPay;
use think\Config;
use think\Log;
class WXPayConstants
{
//'配置'
public $APPID = "";//appid
public $AppSecret="";//appid密钥
public $mch_id="";//商户账号
public $secret="";//商户密钥
public $wxpayCert="";//商户证书
public $wxPayCertKey="";//商户证书密钥
public $url="https://api.mch.weixin.qq.com/pay/unifiedorder";//微信支付
public $refund_url="https://api.mch.weixin.qq.com/secapi/pay/refund";//微信退款
public $pay_url="https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers";//微信企业支付零钱
public $pay_bank_url="https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank";//微信企业支付银行卡
public $APPID = ""; //appid
public $AppSecret = ""; //appid密钥
public $mch_id = ""; //商户账号
public $secret = ""; //商户密钥
public $wxpayCert = ""; //商户证书
public $wxPayCertKey = ""; //商户证书密钥
public $url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; //微信支付
public $refund_url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; //微信退款
public $pay_url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; //微信企业支付零钱
public $pay_bank_url = "https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank"; //微信企业支付银行卡
public $public = "";
public $public_pkcs8 = "";
/**
* 配置
......@@ -30,32 +34,33 @@ class WXPayConstants
*/
public function __construct()
{
// $appconfig = SettingModel::getConfigValue('miniconfig');
// $appconfig = SettingModel::getConfigValue('miniconfig');
$appconfig = Config::get('testConfig');
$this->APPID=$appconfig['app_id'];
$this->AppSecret=$appconfig['appSecret'];
$this->mch_id=$appconfig['mch_id'];
$this->secret=$appconfig['key'];
$this->wxpayCert=$appconfig['cert_path'];
$this->wxPayCertKey=$appconfig['key_path'];
$this->public=$appconfig['public'];
$this->public_pkcs8=$appconfig['public_pkcs8'];
// $this->wxpayCert=Config::get("appConfig.wxpayCert");
// $this->wxPayCertKey=Config::get("appConfig.wxPayCertKey");
$this->APPID = $appconfig['app_id'];
$this->AppSecret = $appconfig['appSecret'];
$this->mch_id = $appconfig['mch_id'];
$this->secret = $appconfig['key'];
$this->wxpayCert = $appconfig['cert_path'];
$this->wxPayCertKey = $appconfig['key_path'];
$this->public = $appconfig['public'];
$this->public_pkcs8 = $appconfig['public_pkcs8'];
// $this->wxpayCert=Config::get("appConfig.wxpayCert");
// $this->wxPayCertKey=Config::get("appConfig.wxPayCertKey");
}
public function getOppid($code){
$data = array (
public function getOppid($code)
{
$data = array(
'appid' => $this->APPID,
'secret' => $this->AppSecret,
'js_code' => $code,
'grant_type' => 'authorization_code',
);
$data = http_build_query($data);
$opts = array (
'http' => array (
$opts = array(
'http' => array(
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencodedrn",
'header' => "Content-type: application/x-www-form-urlencodedrn",
"Content-Length: " . strlen($data) . "rn",
'content' => $data
)
......@@ -68,21 +73,21 @@ class WXPayConstants
/**获取access_token
* @return string
*/
public function getAccessToken(){
public function getAccessToken()
{
//获取access_token
$access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->APPID&secret=$this->AppSecret";
// session_start();
// session_start();
$_SESSION['access_token'] = "";
$_SESSION['expires_in'] = 0;
$ACCESS_TOKEN = "";
if(!isset($_SESSION['access_token']) || (isset($_SESSION['expires_in']) && time() > $_SESSION['expires_in']))
{
if (!isset($_SESSION['access_token']) || (isset($_SESSION['expires_in']) && time() > $_SESSION['expires_in'])) {
$json = WXPayUtils::httpRequest($access_token);
$json = json_decode($json,true);
$json = json_decode($json, true);
$_SESSION['access_token'] = $json['access_token'];
$_SESSION['expires_in'] = time()+7200;
$_SESSION['expires_in'] = time() + 7200;
return $ACCESS_TOKEN = $json["access_token"];
}else{
} else {
return $ACCESS_TOKEN = $_SESSION["access_token"];
}
}
......@@ -90,21 +95,22 @@ class WXPayConstants
/**获取电话号码
* @return string
*/
public static function getuserphonenumber($code,$error){
$that=new static();
$access_token=$that->getAccessToken();
$url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=".$access_token;
if($code) {
$json = patchCurl($url,['code'=>$code]);
if($json->errcode == 0){
public static function getuserphonenumber($code, $error)
{
$that = new static();
$access_token = $that->getAccessToken();
$url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" . $access_token;
if ($code) {
$json = patchCurl($url, ['code' => $code]);
if ($json->errcode == 0) {
return $json->phone_info->purePhoneNumber;
}
$error->code=-3;
$error->msg=$json->errmsg;
$error->code = -3;
$error->msg = $json->errmsg;
return $error;
}
$error->code=-3;
$error->msg="获取code失败";
$error->code = -3;
$error->msg = "获取code失败";
return $error;
}
......@@ -116,85 +122,86 @@ class WXPayConstants
* @param $error
* @return string
*/
public static function enterprisePayment($openid,$body,$out_trade_no,$total_fee,$re_user_name,$error,$login_type=''){
$that=new static();
$nonce_str=WXPayUtils::nonce_str();
if(empty($openid)){
$error->code=-4;
$error->msg="获取openid失败";
public static function enterprisePayment($openid, $body, $out_trade_no, $total_fee, $re_user_name, $error, $login_type = '')
{
$that = new static();
$nonce_str = WXPayUtils::nonce_str();
if (empty($openid)) {
$error->code = -4;
$error->msg = "获取openid失败";
return $error;
}
$params=[
$params = [
"mch_appid" => $that->APPID,
"mchid" => $that->mch_id,
"nonce_str" => $nonce_str,// 随机串,32字符以内
"nonce_str" => $nonce_str, // 随机串,32字符以内
"partner_trade_no" => $out_trade_no,
"openid" => $openid,
"check_name" =>"FORCE_CHECK",
"re_user_name"=>$re_user_name,
"amount" => floatval($total_fee),//floatval($total_fee * 100),// 订单费用,单位:分
"spbill_create_ip"=> $_SERVER['REMOTE_ADDR'],
"desc" =>$body,
"check_name" => "FORCE_CHECK",
"re_user_name" => $re_user_name,
"amount" => floatval($total_fee), //floatval($total_fee * 100),// 订单费用,单位:分
"spbill_create_ip" => $_SERVER['SERVER_ADDR'],
"desc" => $body,
];
//按照要求计算sign
$params['sign'] = WXPayUtils::sign($params,$that->secret);
$params['sign'] = WXPayUtils::sign($params, $that->secret);
// 给微信发出的请求,整个参数是个XML
$post_xml=WXPayUtils::post_xml($params);
$post_xml = WXPayUtils::post_xml($params);
//请求是否成功
$output=WXPayUtils::http_request($that->pay_url,$post_xml,$that->wxpayCert,$that->wxPayCertKey);
$output = WXPayUtils::http_request($that->pay_url, $post_xml, $that->wxpayCert, $that->wxPayCertKey);
if (false === $output) {
$error->code=-10;
$error->msg="请求第三方支付失败";
$error->code = -10;
$error->msg = "请求第三方支付失败";
return $error;
}
$array = WXPayUtils::xml($output);//全要大写
Log::write("返回值".json_encode($array));
$tmp=[];//临时数组用于签名
if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
$array = WXPayUtils::xml($output); //全要大写
Log::write("返回值" . json_encode($array));
$tmp = []; //临时数组用于签名
if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
$time = time();
$tmp['partner_trade_no'] = $array['PARTNER_TRADE_NO'];
$tmp['payment_no']=$array['PAYMENT_NO'];
$tmp['payment_no'] = $array['PAYMENT_NO'];
return $tmp;
}else if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL'){
if($array["ERR_CODE"]=="NO_AUTH"){
$error->code=-3;
$error->msg="没有该接口权限";
} else if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL') {
if ($array["ERR_CODE"] == "NO_AUTH") {
$error->code = -3;
$error->msg = $_SERVER['REMOTE_ADDR'] . "没有该接口权限";
return $error;
}else if($array["ERR_CODE"]=="AMOUNT_LIMIT"){
$error->code=-3;
$error->msg="提现金额超过限制";
} else if ($array["ERR_CODE"] == "AMOUNT_LIMIT") {
$error->code = -3;
$error->msg = "提现金额超过限制";
return $error;
}else if($array["ERR_CODE"]=="PARAM_ERROR"){
$error->code=-3;
$error->msg="参数错误";
} else if ($array["ERR_CODE"] == "PARAM_ERROR") {
$error->code = -3;
$error->msg = "参数错误";
return $error;
}else if($array["ERR_CODE"]=="OPENID_ERROR"){
$error->code=-3;
$error->msg="Openid错误,请重新登录后提现";
} else if ($array["ERR_CODE"] == "OPENID_ERROR") {
$error->code = -3;
$error->msg = "Openid错误,请重新登录后提现";
return $error;
}else if($array["ERR_CODE"]=="NOTENOUGH"){
$error->code=-3;
$error->msg="余额不足";
} else if ($array["ERR_CODE"] == "NOTENOUGH") {
$error->code = -3;
$error->msg = "余额不足";
return $error;
}else if($array["ERR_CODE"]=="SYSTEMERROR"){
$error->code=-3;
$error->msg="系统繁忙,请稍后再试。";
} else if ($array["ERR_CODE"] == "SYSTEMERROR") {
$error->code = -3;
$error->msg = "系统繁忙,请稍后再试。";
return $error;
}else if($array["ERR_CODE"]=="NAME_MISMATCH"){
$error->code=-3;
$error->msg="填写姓名与微信真实姓名不一致";
} else if ($array["ERR_CODE"] == "NAME_MISMATCH") {
$error->code = -3;
$error->msg = "填写姓名与微信真实姓名不一致";
return $error;
}else if($array["ERR_CODE"]=="SIGN_ERROR"){
$error->code=-3;
$error->msg="签名错误,请重新登录后提现";
} else if ($array["ERR_CODE"] == "SIGN_ERROR") {
$error->code = -3;
$error->msg = "签名错误,请重新登录后提现";
return $error;
}else if($array["ERR_CODE"]=="MONEY_LIMIT"){
$error->code=-3;
$error->msg="已经达到今日付款总额上限";
} else if ($array["ERR_CODE"] == "MONEY_LIMIT") {
$error->code = -3;
$error->msg = "已经达到今日付款总额上限";
return $error;
}else{
$error->code=-3;
$error->msg=$array["ERR_CODE_DES"];
} else {
$error->code = -3;
$error->msg = $array["ERR_CODE_DES"];
return $error;
}
}
......@@ -210,9 +217,12 @@ class WXPayConstants
* @params string $desc : 付款备注
* return string $payment_no :支付成功的订单号
*/
public static function payForBank($out_trade_no,$amount,$enc_bank_no,$enc_true_name,$bank_code,$desc='企业付款到银行卡',$error)
public static function payForBank($out_trade_no, $amount, $enc_bank_no, $enc_true_name, $bank_code, $desc = '企业付款到银行卡', $error)
{
$that=new static();
$error->code = -10;
$error->msg = "暂不支持打款到银行卡";
return $error;
$that = new static();
$data['amount'] = $amount;
$data['bank_code'] = $bank_code;
$data['desc'] = $desc;
......@@ -222,109 +232,108 @@ class WXPayConstants
$data['nonce_str'] = $that->random(12);
$data['partner_trade_no'] = $out_trade_no;
//按照要求计算sign
$data['sign'] = WXPayUtils::sign($data,$that->secret);
$data['sign'] = WXPayUtils::sign($data, $that->secret);
// 给微信发出的请求,整个参数是个XML
$post_xml=WXPayUtils::post_xml($data);
$post_xml = WXPayUtils::post_xml($data);
//请求是否成功
$output=WXPayUtils::http_request($that->pay_bank_url,$post_xml,$that->wxpayCert,$that->wxPayCertKey);
$output = WXPayUtils::http_request($that->pay_bank_url, $post_xml, $that->wxpayCert, $that->wxPayCertKey);
if (false === $output) {
$error->code=-10;
$error->msg="请求第三方支付失败";
$error->code = -10;
$error->msg = "请求第三方支付失败";
return $error;
}
$array = WXPayUtils::xml($output);//全要大写
Log::write("返回值".json_encode($array));
$tmp=[];//临时数组用于签名
if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
$array = WXPayUtils::xml($output); //全要大写
Log::write("返回值" . json_encode($array));
$tmp = []; //临时数组用于签名
if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
$time = time();
$tmp['partner_trade_no'] = $array['PARTNER_TRADE_NO'];
$tmp['payment_no']=$array['PAYMENT_NO'];
$tmp['payment_no'] = $array['PAYMENT_NO'];
return $tmp;
}else if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL'){
$error-> code= -3;
$error-> RETURN_CODE= $array['RETURN_CODE'] ;
$error-> RESULT_CODE= $array['RESULT_CODE'] ;
$error->msg= $array["ERR_CODE_DES"];
} else if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL') {
$error->code = -3;
$error->RETURN_CODE = $array['RETURN_CODE'];
$error->RESULT_CODE = $array['RESULT_CODE'];
$error->msg = $array["ERR_CODE_DES"];
return $error;
}
}
//微信退款功能
public function wxminiOutRefund($out_trade_no,$total_fee,$error,$login_type=''){
public function wxminiOutRefund($out_trade_no, $total_fee, $error, $login_type = '')
{
$config = SettingModel::getConfigValue('miniconfig');
$wxRefundResponseURl=$config['NotifyUrl'];
if($login_type=='app'){
$wxRefundResponseURl = $config['NotifyUrl'];
if ($login_type == 'app') {
$config = SettingModel::getConfigValue('appconfig');
$this->APPID=$config['app_id'];
$wxRefundResponseURl=$config['NotifyUrl'];
$this->APPID = $config['app_id'];
$wxRefundResponseURl = $config['NotifyUrl'];
}
$nonce_str=WXPayUtils::nonce_str();
$params=[
$nonce_str = WXPayUtils::nonce_str();
$params = [
"appid" => $this->APPID,
"mch_id" => $this->mch_id,
"nonce_str" => $nonce_str,// 随机串,32字符以内
"nonce_str" => $nonce_str, // 随机串,32字符以内
"out_trade_no" => $out_trade_no,
"out_refund_no" => $out_trade_no,
"total_fee" => floatval($total_fee),//floatval($total_fee * 100),// 订单费用,单位:分
"refund_fee"=> floatval($total_fee),
"total_fee" => floatval($total_fee), //floatval($total_fee * 100),// 订单费用,单位:分
"refund_fee" => floatval($total_fee),
"notify_url" => $wxRefundResponseURl,
];
//按照要求计算sign
$params['sign'] = WXPayUtils::sign($params,$this->secret);//商户秘钥
$params['sign'] = WXPayUtils::sign($params, $this->secret); //商户秘钥
// 给微信发出的请求,整个参数是个XML
$post_xml=WXPayUtils::post_xml($params);
$post_xml = WXPayUtils::post_xml($params);
//请求是否成功
$output=WXPayUtils::http_request($this->refund_url,$post_xml,$this->wxpayCert,$this->wxPayCertKey);
$output = WXPayUtils::http_request($this->refund_url, $post_xml, $this->wxpayCert, $this->wxPayCertKey);
if (false === $output) {
$error->code=-10;
$error->msg="请求第三方支付失败";
$error->code = -10;
$error->msg = "请求第三方支付失败";
echo $error->msg;
return $error;
}
$array = WXPayUtils::xml($output);//全要大写
$data=[];//临时数组用于签名
$array = WXPayUtils::xml($output); //全要大写
$data = []; //临时数组用于签名
//Log::record("==app支付调起 <pre>".json_encode($array). "<pre>" . "失败", 'debug');//记录错误
if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS') {
$data['appid'] = $array['APPID'];
$data['mch_id'] =$array['MCH_ID'];
$data['refund_fee'] =$array['REFUND_FEE'];
$data['total_fee'] =$array['TOTAL_FEE'];
$data['mch_id'] = $array['MCH_ID'];
$data['refund_fee'] = $array['REFUND_FEE'];
$data['total_fee'] = $array['TOTAL_FEE'];
return $data;
}else if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL'){
if($array["ERR_CODE"]=="BIZERR_NEED_RETRY"){
$error->code=-3;
$error->msg="并发情况下,业务被拒绝,商户重试即可解决";
} else if ($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'FAIL') {
if ($array["ERR_CODE"] == "BIZERR_NEED_RETRY") {
$error->code = -3;
$error->msg = "并发情况下,业务被拒绝,商户重试即可解决";
//echo $error->msg;
return $error;
}else if($array["ERR_CODE"]=="TRADE_OVERDUE"){
$error->code=-3;
$error->msg=" 订单已经超过可退款的最大期限(支付后一年内可退款)";
} else if ($array["ERR_CODE"] == "TRADE_OVERDUE") {
$error->code = -3;
$error->msg = " 订单已经超过可退款的最大期限(支付后一年内可退款)";
//echo $error->msg;
return $error;
}else if($array["ERR_CODE"]=="ERROR"){
$error->code=-3;
$error->msg="申请退款业务发生错误";
} else if ($array["ERR_CODE"] == "ERROR") {
$error->code = -3;
$error->msg = "申请退款业务发生错误";
//echo $error->msg;
return $error;
}else if($array["ERR_CODE"]=="USER_ACCOUNT_ABNORMAL"){
$error->code=-3;
$error->msg="用户帐号注销";
} else if ($array["ERR_CODE"] == "USER_ACCOUNT_ABNORMAL") {
$error->code = -3;
$error->msg = "用户帐号注销";
//echo $error->msg;
return $error;
}else if($array["ERR_CODE"]=="SIGNERROR"){
$error->code=-3;
$error->msg="签名错误";
} else if ($array["ERR_CODE"] == "SIGNERROR") {
$error->code = -3;
$error->msg = "签名错误";
//echo $error->msg;
return $error;
}else if($array["ERR_CODE"]=="NOTENOUGH"){
$error->code=-3;
$error->msg="商户可用退款余额不足";
} else if ($array["ERR_CODE"] == "NOTENOUGH") {
$error->code = -3;
$error->msg = "商户可用退款余额不足";
//echo $error->msg;
return $error;
}else{
$error->code=-3;
$error->msg="对不起,微信退款接口调用错误!";
} else {
$error->code = -3;
$error->msg = "对不起,微信退款接口调用错误!";
//echo $error->msg;
return $error;
}
......@@ -339,17 +348,17 @@ class WXPayConstants
*/
private function publicEncrypt($data)
{
// $public_Pkcs8=SettingModel::getConfigChildValue('appconfig',"publicPkcs8");
// $publicPkcs8=APP_PATH."admin/utils/".$public_Pkcs8;
// $public_Pkcs8=SettingModel::getConfigChildValue('appconfig',"publicPkcs8");
// $publicPkcs8=APP_PATH."admin/utils/".$public_Pkcs8;
$publicPkcs8 = $this->public_pkcs8;
// 进行加密
$pubkey = openssl_pkey_get_public(file_get_contents($publicPkcs8));
$encrypt_data = '';
$encrypted = '';
$r = openssl_public_encrypt($data,$encrypt_data,$pubkey,OPENSSL_PKCS1_OAEP_PADDING);
if($r){//加密成功,返回base64编码的字符串
return base64_encode($encrypted.$encrypt_data);
}else{
$r = openssl_public_encrypt($data, $encrypt_data, $pubkey, OPENSSL_PKCS1_OAEP_PADDING);
if ($r) { //加密成功,返回base64编码的字符串
return base64_encode($encrypted . $encrypt_data);
} else {
return false;
}
}
......@@ -361,23 +370,23 @@ class WXPayConstants
private function get_pub_key()
{
$config = SettingModel::getConfigValue('miniconfig');
$rsafile=$config['rsafile'];
if(!is_file($rsafile)){
$rsafile = $config['rsafile'];
if (!is_file($rsafile)) {
$data['mch_id'] = $this->mch_id;
$data['nonce_str'] = $this->random(12);
$data['sign'] = WXPayUtils::sign($data,$this->secret);
$post_xml=WXPayUtils::post_xml($data);
$data['sign'] = WXPayUtils::sign($data, $this->secret);
$post_xml = WXPayUtils::post_xml($data);
$url = 'https://fraud.mch.weixin.qq.com/risk/getpublickey';
$output = WXPayUtils::http_request($url,$post_xml,$this->wxpayCert,$this->wxPayCertKey);
$ret = WXPayUtils::xml($output);//全要大写
if($ret['RETURN_CODE'] == 'SUCCESS' && isset($ret['PUB_KEY'])){
file_put_contents($rsafile,$ret['PUB_KEY']);
$output = WXPayUtils::http_request($url, $post_xml, $this->wxpayCert, $this->wxPayCertKey);
$ret = WXPayUtils::xml($output); //全要大写
if ($ret['RETURN_CODE'] == 'SUCCESS' && isset($ret['PUB_KEY'])) {
file_put_contents($rsafile, $ret['PUB_KEY']);
return $ret['pub_key'];
}else{
} else {
return null;
}
}else{
} else {
return file_get_contents($rsafile);
}
}
......@@ -389,27 +398,175 @@ class WXPayConstants
* @param int $convert 转换大小写 1大写 0小写
* @return string
*/
private function random($length=10,$type='letter',$convert=false)
private function random($length = 10, $type = 'letter', $convert = false)
{
$config = array(
'number'=>'1234567890',
'letter'=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'string'=>'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
'all'=>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
'number' => '1234567890',
'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
);
if(!isset($config[$type])) $type = 'letter';
if (!isset($config[$type])) $type = 'letter';
$string = $config[$type];
$code = '';
$strlen = strlen($string) -1;
for($i = 0; $i < $length; $i++){
$strlen = strlen($string) - 1;
for ($i = 0; $i < $length; $i++) {
$code .= $string[mt_rand(0, $strlen)];
}
if(!empty($convert)){
$code = ($convert > 0)? strtoupper($code) : strtolower($code);
if (!empty($convert)) {
$code = ($convert > 0) ? strtoupper($code) : strtolower($code);
}
return $code;
}
}
\ No newline at end of file
/**
* @notes 商家转账到零钱
*/
public static function transfer($openid, $body, $out_trade_no, $total_fee, $re_user_name, $error, $login_type = '')
{
$that = new static();
//请求URL
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
//请求方式
$http_method = 'POST';
//请求参数
$data = [
'appid' => $that->APPID, //申请商户号的appid或商户号绑定的appid(企业号corpid即为此appid)
'out_batch_no' => 'ycz' . date('Ymd') . mt_rand(1000, 9999), //商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
'batch_name' => $body, //该笔批量转账的名称
'batch_remark' => $body, //转账说明,UTF8编码,最多允许32个字符
'total_amount' => floatval($total_fee), //转账金额单位为“分”。转账总金额必须与批次内所有明细转账金额之和保持一致,否则无法发起转账操作
'total_num' => 1, //一个转账批次单最多发起三千笔转账。转账总笔数必须与批次内所有明细之和保持一致,否则无法发起转账操作
'transfer_detail_list' => [
[ //发起批量转账的明细列表,最多三千笔
'out_detail_no' => $out_trade_no, //商户系统内部区分转账批次单下不同转账明细单的唯一标识,要求此参数只能由数字、大小写字母组成
'transfer_amount' => floatval($total_fee), //转账金额单位为分
'transfer_remark' => $body, //单条转账备注(微信用户会收到该备注),UTF8编码,最多允许32个字符
'openid' => $openid, //openid是微信用户在公众号appid下的唯一用户标识(appid不同,则获取到的openid就不同),可用于永久标记一个用户
]
]
];
$token = self::token($url, $http_method, $data); //获取token
Log::write("token:" . $token);
$result = self::https_request($url, json_encode($data), $token); //发送请求
$result_arr = json_decode($result, true);
if (!isset($result_arr['create_time'])) { //批次受理失败
throw new \Exception($result_arr['message']);
}
//批次受理成功,进行操作
return true;
}
/**
* @notes 获取签名
*/
public static function token($url, $http_method, $data)
{
$that = new static();
$timestamp = time(); //请求时间戳
$url_parts = parse_url($url); //获取请求的绝对URL
$nonce = $timestamp . rand('10000', '99999'); //请求随机串
$body = empty($data) ? '' : json_encode((object)$data); //请求报文主体
$stream_opts = [
"ssl" => [
"verify_peer" => false,
"verify_peer_name" => false,
]
];
$apiclient_cert_arr = openssl_x509_parse(file_get_contents($that->wxpayCert, false, stream_context_create($stream_opts)));
$serial_no = $apiclient_cert_arr['serialNumberHex']; //证书序列号
$mch_private_key = file_get_contents($that->wxPayCertKey, false, stream_context_create($stream_opts)); //密钥
$merchant_id = $that->mch_id; //商户id
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
$message = $http_method . "\n" .
$canonical_url . "\n" .
$timestamp . "\n" .
$nonce . "\n" .
$body . "\n";
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
$sign = base64_encode($raw_sign); //签名
$schema = 'WECHATPAY2-SHA256-RSA2048';
$token = sprintf(
'mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
$merchant_id,
$nonce,
$timestamp,
$serial_no,
$sign
); //微信返回token
return $schema . ' ' . $token;
}
/**
* @notes 发送请求
*/
public static function https_request($url, $data, $token)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, (string)$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//添加请求头
$headers = [
'Authorization:' . $token,
'Accept: application/json',
'Content-Type: application/json; charset=utf-8',
'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
];
if (!empty($headers)) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
/**
* @notes 敏感信息加解密
*/
public static function getEncrypt($str)
{
$that = new static();
//$str是待加密字符串
$public_key = file_get_contents($that->wxpayCert);
$encrypted = '';
if (openssl_public_encrypt($str, $encrypted, $public_key, OPENSSL_PKCS1_OAEP_PADDING)) {
//base64编码
$sign = base64_encode($encrypted);
} else {
throw new \Exception('encrypt failed');
}
return $sign;
}
/**
* @notes 商家明细单号查询
*/
public static function detailsQuery($withdrawApply)
{
//请求URL
$url = 'https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/' . $withdrawApply['batch_no'] . '/details/out-detail-no/' . $withdrawApply['sn'];
//请求方式
$http_method = 'GET';
//请求参数
$data = [];
$token = self::token($url, $http_method, $data); //获取token
$result = self::https_request($url, $data, $token); //发送请求
$result_arr = json_decode($result, true);
return $result_arr;
}
}
......@@ -43,11 +43,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'mobile', title: __('Mobile'), operate: 'LIKE',visible:false},
{field: 'identity_number', title: __('Identity_number'), operate: 'LIKE',visible:true},
{field: 'parent_user_id', title: __('Parent_user_id'), operate: false,visible:false},
{field: 'area.MergerName', title: __('所属区域')},
// {field: 'area.MergerName', title: __('所属区域')},
/* {field: 'city_id', title: __('City_id')},
{field: 'area_id', title: __('Area_id')},*/
{field: 'detail_address', title: __('Detail_address'), operate: 'LIKE'},
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.status},
// {field: 'detail_address', title: __('Detail_address'), operate: 'LIKE'},
// {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.status},
{field: 'deviceCount', title: __('deviceCount'), operate: 'LIKE'},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment