|
| 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 | +?> |
0 commit comments