【支付集成】三一支付/Payment 集成至系统中

有乎| 阅读:186 发表时间:2019-05-16 10:37:48 杂项

声明:属于第四方支付,费率高。

聚合支付:三一支付的集成

第一步:生成并提交订单,【简单处理回调:attach参数里传入会员的ID】

$order_id = "E".time().rand(1000, 9999);
$money    = 100;

//开始POST
//订单号
			$pay_amount = $money;    //交易金额
			$pay_applydate = date("Y-m-d H:i:s");  //订单时间
			$pay_notifyurl = "http://".$_SERVER['HTTP_HOST']."/notify.php";   //服务端返回地址
			$pay_callbackurl = "http://".$_SERVER['HTTP_HOST']."/return.php";  //页面跳转返回地址
			$Md5key = "商户后台的KEY";   //商户后台API管理获取
			$tjurl = "http://www.changxiana.cn/Pay_Index.html";   //提交地址
			$pay_bankcode = "通道ID"; //支付宝扫码  //商户后台通道费率页 获取银行编码
			$native = array(
				"pay_memberid" => $pay_memberid,
				"pay_orderid" => $pay_orderid,
				"pay_amount" => $pay_amount,
				"pay_applydate" => $pay_applydate,
				"pay_bankcode" => $pay_bankcode,
				"pay_notifyurl" => $pay_notifyurl,
				"pay_callbackurl" => $pay_callbackurl,
			);
			ksort($native);
			$md5str = "";
			foreach ($native as $key => $val) {
				$md5str = $md5str . $key . "=" . $val . "&";
			}
			$sign = strtoupper(md5($md5str . "key=" . $Md5key));
			$native["pay_md5sign"] = $sign;
			$native['pay_attach'] = "";
			$native['pay_productname'] ='会员充值';
			
			$params = "";
			
			foreach ($native as $key => $val) {
				$params .= '<input type="hidden" name="' . $key . '" value="' . $val . '">';
			}
			exit('<!DOCTYPE html>
					<html lang="zh-CN">
					<head>
						<meta charset="utf-8">
						<meta http-equiv="X-UA-Compatible" content="IE=edge">
						<meta name="viewport" content="width=device-width, initial-scale=1">
						<title>支付</title>
						<!-- Bootstrap -->
						<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
							  integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
						<!--[if lt IE 9]>
						<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
						<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
						<![endif]-->
					</head>
					<body>
					<div class="container">
						<div class="row" style="margin:15px;0;">
							<div class="col-md-12">
								<form id="form1" class="form-inline" method="post" action="'.$tjurl.'">'									
									.$params.'
								</form>
							</div>
						</div>
					</div>
					<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
					<script>
					   $("#form1").submit();
					</script>
					</body>
					</html>');

第二步:提交支付后两个页面: 

1、return.php  【代码很简单,没有操作,只有一个跳转动作,回调程序处理放在notify里】

header('Content-type:text/html;charset=utf-8');
	    $returnArray = array( // 返回字段
			"memberid" => $_REQUEST["memberid"], // 商户ID
			"orderid" =>  $_REQUEST["orderid"], // 订单号
			"amount" =>  $_REQUEST["amount"], // 交易金额
			"datetime" =>  $_REQUEST["datetime"], // 交易时间
			"transaction_id" =>  $_REQUEST["transaction_id"], // 流水号
			"returncode" => $_REQUEST["returncode"]
		);
		$md5key = "91yy0yklihhfth4lr6dof1mpsqcvmuuw"; //商户APIKEY,商户后台API管理获取
		ksort($returnArray);
		reset($returnArray);
		$md5str = "";
		foreach ($returnArray as $key => $val) {
			$md5str = $md5str . $key . "=" . $val . "&";
		}
		$sign = strtoupper(md5($md5str . "key=" . $md5key)); 
		if ($sign == $_REQUEST["sign"]) {
			if ($_REQUEST["returncode"] == "00") {
				    "交易成功!订单号:".$_REQUEST["orderid"];
				   exit('<!DOCTYPE html>
					<html lang="zh-CN">
					<head>
						<meta charset="utf-8">
						<meta http-equiv="X-UA-Compatible" content="IE=edge">
						<meta name="viewport" content="width=device-width, initial-scale=1">
						<title>支付</title>
						<!-- Bootstrap -->
						<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
							  integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
						<!--[if lt IE 9]>
						<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
						<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
						<![endif]-->
					</head>
					<body>
					<div class="container">
						<div class="row" style="margin:15px;0;">
							<div class="col-md-12" align="center">
							   '.$str.'
							</div>
						</div>
					</div>
					<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
					<script>
					  setTimeout(function(){location.href="/site/user"}, 1500);
					</script>
					</body>
					</html>');
			}
		}

2、notify.php 【接收回调,并处理具体逻辑】

header('Content-type:text/html;charset=utf-8');
		$attach = $_REQUEST['attach'];
	   $returnArray = array( // 返回字段
				"memberid" => $_REQUEST["memberid"], // 商户ID
				"orderid" =>  $_REQUEST["orderid"], // 订单号
				"amount" =>  $_REQUEST["amount"], // 交易金额
				"datetime" =>  $_REQUEST["datetime"], // 交易时间
				"transaction_id" =>  $_REQUEST["transaction_id"], // 支付流水号
				"returncode" => $_REQUEST["returncode"],
			);
			$md5key = "t4ig5acnpx4fet4zapshjacjd9o4bhbi";
			ksort($returnArray);
			reset($returnArray);
			$md5str = "";
			foreach ($returnArray as $key => $val) {
				$md5str = $md5str . $key . "=" . $val . "&";
			}
			$sign = strtoupper(md5($md5str . "key=" . $md5key));
			if ($sign == $_REQUEST["sign"]) {
				if ($_REQUEST["returncode"] == "00") {
					//TODO:处理充值  
					
                                        //处理完成后返回OK
					exit('ok');
				}
			}
*文章为作者独立观点,不代表【uuuho有乎】的立场
本文由【uuuho有乎】发表并编辑,转载此文章须经作者同意,并请附上出处及本页链接。如有侵权,请联系本站删除。