Skip to content

Commit 6febbe4

Browse files
authored
个人免签支付PHP接入代码DEMO
个人免签支付PHP接入代码DEMO
1 parent a3e17ee commit 6febbe4

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

gogozhifu-demo-php/notify.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/* GOGO支付接入代码DEMO - PHP版本 */
3+
4+
ini_set("error_reporting", "E_ALL & ~E_NOTICE");
5+
$appId = "填入GOOG支付商户自己的AppId"; //APPID
6+
$appSecret = "填入GOOG支付商户自己的AppSecret"; //APPSECRET
7+
8+
//获取回调的参数(回调请求是POST方式,参数获取同时支持GET、POST)
9+
$payId = $_GET['payId'];//商户订单号
10+
$param = $_GET['param'];//创建订单的时候传入的参数
11+
$type = $_GET['type'];//支付方式 :微信支付为1 支付宝支付为2
12+
$price = $_GET['price'];//订单金额
13+
$reallyPrice = $_GET['reallyPrice'];//实际支付金额
14+
$sign = $_GET['sign'];//校验签名,计算方式 = md5(appId + payId + param + type + price + reallyPrice + appSecret)
15+
16+
//开始校验签名
17+
$_sign = md5($appId . $payId . $param . $type . $price . $reallyPrice . $appSecret);
18+
if ($_sign != $sign) {
19+
echo "error_sign";//sign校验不通过
20+
exit();
21+
}
22+
echo "success";
23+
//继续处理商户自己的业务流程
24+
//echo "商户订单号:" . $payId . "<br>自定义参数:" . $param . "<br>支付方式:" . $type . "<br>订单金额:" . $price . "<br>实际支付金额:" . $reallyPrice;
25+
?>

gogozhifu-demo-php/pay.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/* GOGO支付接入代码DEMO - PHP版本 */
3+
4+
pay(1, 0.18, 'go-test-' . time());
5+
6+
// $type支付类型(1:微信,2支付宝);$price产品价格,支持到小数点后两位;$payId不重复的交易单号
7+
function pay($type, $price, $payId)
8+
{
9+
// GOGO支付创建订单API地址
10+
$apiUrl = 'https://www.gogozhifu.com/shop/api/createOrder';
11+
12+
// 选填,支付完成后通知开发者服务器的url。(不传会获取GOGO支付商户后台设置的默认回调地址)
13+
//这里要修改成商户自己接收支付成功回调通知的地址,该地址不能有访问权限,POST请求方式
14+
$notifyUrl = 'http://localhost/notify.php';
15+
16+
// 选填,跳转页面url。(不传会获取GOGO支付商户后台设置的默认跳转地址)
17+
$returnUrl = 'http://localhost/return.php';
18+
19+
// 选填, 商户自定义的参数,回调通知的时候会原样返回
20+
$param = 'GOTEST';
21+
22+
// 计算sign
23+
$sign = md5(getAppId() . $payId . $param . $type . $price . getAppSecret());
24+
25+
$data = array(
26+
'payId' => $payId,
27+
'param' => $param,
28+
'type' => $type,
29+
'price' => $price,
30+
'sign' => $sign,
31+
'notifyUrl' => $notifyUrl,
32+
'returnUrl' => $returnUrl,
33+
'isHtml' => 1
34+
);
35+
$ret = goPost($apiUrl, $data);
36+
echo $ret;
37+
}
38+
39+
// 必需,填入商户自己的AppId
40+
function getAppId()
41+
{
42+
return "填入GOOG支付商户自己的AppId";
43+
}
44+
45+
// 必需,填入商户自己的AppSecret
46+
function getAppSecret()
47+
{
48+
return "填入GOOG支付商户自己的AppSecret";
49+
}
50+
51+
// 发起POST请求,请求头里必须设置商户的App-Id和App-Secret
52+
function goPost($url, $data)
53+
{
54+
$headerArray = [
55+
"App-Id: " . getAppId(),
56+
"App-Secret: " . getAppSecret(),
57+
];
58+
$curl = curl_init();
59+
curl_setopt($curl, CURLOPT_URL, $url);
60+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
61+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
62+
curl_setopt($curl, CURLOPT_POST, 1);
63+
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
64+
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
65+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
66+
$output = curl_exec($curl);
67+
curl_close($curl);
68+
return $output;
69+
}
70+
71+
?>

gogozhifu-demo-php/return.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
/* GOGO支付接入代码DEMO - PHP版本 */
3+
4+
echo '支付成功!GOGO支付帮你跳转这个页面了~';
5+
?>

0 commit comments

Comments
 (0)