0
点赞
收藏
分享

微信扫一扫

靳宇灵 | 个人日常提升技能记录,无需参考:增加支付方式

1./system/modules/pay 下新增文件 newpay_url.action.php


<?php
defined('G_IN_SYSTEM')or exit('No permission resources.');
ini_set("display_errors","OFF");
System::load_sys_fun('send');
class xxpay_url extends SystemAction {
public function __construct(){			
$this->db=System::load_sys_class('model');		
public function qiantai(){	
	_messagemobile("支付成功!",WEB_PATH."/mobile/home/userbalance");
  	exit;
}

public function houtai(){
    $data1 = file_get_contents("php://input");
    $data2 = $_POST;
    $data3 = $_GET;
    $data4 = $_REQUEST;
    
    file_put_contents('pay_test_log.txt',"##############"."\r\n",FILE_APPEND);
    file_put_contents('pay_test_log.txt',date('Y-m-d H:i:s')."\r\n",FILE_APPEND); 
    file_put_contents('pay_test_log.txt',"post文件参数:".var_export($data1,true)."\r\n",FILE_APPEND);
    file_put_contents('pay_test_log.txt',"post参数:".var_export($data2,true)."\r\n",FILE_APPEND);
    file_put_contents('pay_test_log.txt',"get参数:".var_export($data3,true)."\r\n",FILE_APPEND);
    file_put_contents('pay_test_log.txt',"所有请求参数:".var_export($data4,true)."\r\n",FILE_APPEND);
    file_put_contents('pay_test_log.txt',"##############"."\r\n"."\r\n",FILE_APPEND);
     
    
    $data = $_POST;
    
   // //测试用
   // $data = [
   //       'payNo' => '20230606103250payin9dyset',
//           'amount' => '10.0',
//           'orderNo' => 'C16860583700692062',
//           'merchantId' => '29122e44899a43fab0c2fce291aeaf3e',
//           'amountReal' => '10.0',
//           'sign' => 'bBbvyNLqDhWoUBRSDlGmyaoF13c=',
//           'status' => '2',
//   ];
    
    $orderid = $data["orderNo"];
	if(!$data  || $data['status'] != 2){	
		echo 'fail';
		exit;
	}
	$this->db->Autocommit_start();
	$dingdaninfo = $this->db->GetOne("select * from `@#_member_addmoney_record` where `code` = '$orderid' and `status` = '未付款' for update");
	//没有该订单,失败
	if(!$dingdaninfo){	
		echo 'fail';
		exit;
	}	
	$c_money = intval($dingdaninfo['money']);
	$uid = $dingdaninfo['uid'];
	$time = time();
	$config = System::load_app_config("userrecharge");
	if($config['r_money']){
		$d_money=$config['r_money'];
	}
	//充值奖励处理
	if($c_money >= $d_money && $config['isOpen']){ 
			if($config['money']){ 
				$m=$config['money'];//充值赠送
				$up_sql1 = $this->db->Query("UPDATE `@#_member` SET `money` = `money` + $m where (`uid` = '$uid')");
				$up_sql3 = $this->db->Query("INSERT INTO `@#_member_rechange` (`uid`, `type`, `pay`, `content`, `money`, `time`) VALUES ('$uid', '1', '账户', '充值赠送', '$m', '$time')");
			} 
			$r_time=$this->db->GetOne("SELECT * FROM `@#_recharge_money` WHERE `uid` = '$uid' AND status=1");
			if(!$r_time){//判断是否在累计时效内
				$status=1;
				//写入充值时间做累计领取判断
				$up_sql2 = $this->db->Query("INSERT INTO `@#_recharge_money` (`uid`, `time`, `dindancode`, `status`) VALUES ('$uid', '$time', '$orderid', '$status')");	
			} 			  		
	}
	
	$up_q1 = $this->db->Query("UPDATE `@#_member_addmoney_record` SET `status` = '已付款' where  `code` = '$orderid'");
	$up_q2 = $this->db->Query("UPDATE `@#_member` SET `money` = `money` + $c_money where (`uid` = '$uid')");				
	$up_q3 = $this->db->Query("INSERT INTO `@#_member_rechange` (`uid`, `type`, `pay`, `content`, `money`, `time`,`orderid`) VALUES ('$uid', '1', '账户', '充值', '$c_money', '$time','$orderid')");
	
	//写入总消费记录,查询该用户的总消费记录
	$commission_data = $this->db->GetOne("SELECT * FROM `@#_member_commission` WHERE `uid`='$uid'");
	if(empty($commission_data)){
	    //没有插入
	    $this->db->Query("INSERT INTO `@#_member_commission`(`uid`,`total_recharge`) values('$uid','$c_money')");
	}else{
	    //有更新
	    $this->db->Query("UPDATE `@#_member_commission` SET `total_recharge`='$c_money'+`total_recharge` WHERE `uid`='$uid'");
	}
		
	if($up_q1 && $up_q2 && $up_q3){
		$this->db->Autocommit_commit();
	}else{
		$this->db->Autocommit_rollback();
		echo 'fail';
		exit;
	}			
     
    echo("success");exit;//返回支付成功标识
}
}
?>

2./system/modules/pay/lib 下新增文件 newpay.class.php


<?php
class xxpay
{
/**
 * @param array $params
 * @return string
 */
public function xxpaysign($params = array())
{
    $new_params = array_filter($params, function($value) {
      return !is_null($value);
    });
    ksort($new_params);
    $param_str = '';
    foreach($new_params as $key => $value) {
      $param_str .= $key.'='.$value.'&';
    }
    $param_str = rtrim($param_str, '&');
    $param_str .= '&'.'&appKey=3243214213423142132143214213423421342342134213';
    $sign = md5($param_str);
    $sign = strtolower($sign);
    return $sign;
}

//post请求
function postCurl($url,$data,$sign){
    $ch = curl_init();//新建curl
    curl_setopt($ch, CURLOPT_POST, true);//post请求
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//开启返回值
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);//获取内容,不直接输出
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "sign:$sign",
            "keyId:1111111111111111",
        )
    );//请求头
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//post传输内容
    curl_setopt($ch, CURLOPT_TIMEOUT,10);//过期时间
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);//不验证公域名
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);//不验证ssl证书
    curl_setopt($ch, CURLOPT_URL, $url);//请求地址url
    $res =  curl_exec($ch); //输出
    curl_close($ch);//关闭
    if($res===false){
        exit('error request!');
    }
    $arr= json_decode($res,true);
    return $arr;
}
}
?>

3./system/modules/pay/lib 下新增文件 pay.class.php addmoney_record方法内增加一个支付方式判断:

//xxpay 支付,开始
	if($pay_type['pay_class']== 'newpay'){
	     $params = [
	         'title'  =>  'Allen',//订单主题
	         'outTradeNo'  =>$dingdancode,//外部订单号
	         'payAmount'  =>  (string)$money,//支付金额 单位雷亚,两位小数
	         'callbackUrl'  =>  G_WEB_PATH.'/index.php/pay/'.$pay_type['pay_class'].'_url/houtai',  //支付结果回调地址  后台通知,//异步回调地址
	         'phone'  => $this->members['mobile'],//用户真实手机号,不需要国际区号 9774867890
	         'returnUrl'  =>  G_WEB_PATH.'/index.php/pay/'.$pay_type['pay_class'].'_url/qiantai',//同步返回地址,支付完成后,跳转的商户页面,必须为https
	         'firstname'  =>  'firstname',//用户真实姓名
	         'lastname'  =>  'lastname',//用户真实姓名
	     ];
	     
	     $key = $pay_type['pay_key']['key']['val'];//秘钥
	    
	     $url="https://api.getnbpay.com/payment/create";
	     
	     $sign = $paydb->newpaysign($params);

	     $res = $paydb->postCurl($url,$params,$sign);
        //  print_r($res).exit;
         if(!empty($res)){
             if($res['code'] != 200) exit($res['msg']);
             $jsonDataUrl = $res['data']['jumpUrl'];
             header("location:".$jsonDataUrl);exit;
         }
	}



举报
0 条评论