Skip to content

Commit 0df0a98

Browse files
committed
🎬Update Webman usage example
1 parent 9c9eafd commit 0df0a98

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

example/common.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
require '../vendor/autoload.php';
33
require 'data/token.php';
4-
function route(bool $boolean, callable $callback)
4+
function routeMap(bool $boolean, callable $callback)
55
{
66
if ($boolean) {
77
$callback();
@@ -11,6 +11,10 @@ function route(bool $boolean, callable $callback)
1111

1212
function getCurrentUrl()
1313
{
14+
if ($opt && isset($opt['webman']) && isset($opt['webman']['request'])) {
15+
$request = $opt['webman']['request'];
16+
return 'http' . ($request->getLocalPort() === 443 ? 's' : '') . ':' . $request->fullUrl();
17+
}
1418
return 'http' . ($_SERVER['HTTPS'] === 'on' ? 's' : '') .
1519
'://' . $_SERVER['HTTP_HOST'] .
1620
(in_array($_SERVER['SERVER_PORT'], array(80, 443, '')) ? '' : ':' . $_SERVER['SERVER_PORT']) .

example/index.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
'is_sandbox' => true,
1515
));
1616
$currentUrl = getCurrentUrl();
17+
/* Webman: please pass (Request $request)
18+
$currentUrl = getCurrentUrl(array('webman' => array('request' => $request))); */
1719
$type = $_GET['type'] ?? '';
18-
route($type === 'pay/cashier', function () use (&$alipayGlobal, $currentUrl) {
20+
routeMap($type === 'pay/cashier', function () use (&$alipayGlobal, $currentUrl) {
1921
try {
2022
$result = $alipayGlobal->payCashier(array(
2123
'customer_belongs_to' => CustomerBelongsTo::ALIPAY_CN, // *
@@ -47,7 +49,7 @@
4749
}
4850
});
4951

50-
route($type === 'auth/consult', function () use (&$alipayGlobal, $currentUrl) {
52+
routeMap($type === 'auth/consult', function () use (&$alipayGlobal, $currentUrl) {
5153
$auth_state = IdTool::CreateAuthState();
5254
try {
5355
$result = $alipayGlobal->authConsult(array(
@@ -65,7 +67,7 @@
6567
}
6668
});
6769

68-
route($type === 'auth/apply_token/auth_code', function () use (&$alipayGlobal) {
70+
routeMap($type === 'auth/apply_token/auth_code', function () use (&$alipayGlobal) {
6971
$auth_code = $_GET['authCode'] ?? '';
7072
try {
7173
$result = $alipayGlobal->authApplyToken(array(
@@ -88,7 +90,7 @@
8890
}
8991
});
9092

91-
route($type === 'auth/apply_token/refresh_token', function () use (&$alipayGlobal) {
93+
routeMap($type === 'auth/apply_token/refresh_token', function () use (&$alipayGlobal) {
9294
$refresh_token = $_GET['refreshToken'] ?? '';
9395
try {
9496
$result = $alipayGlobal->authApplyToken(array(
@@ -111,7 +113,7 @@
111113
}
112114
});
113115

114-
route($type === 'pay/agreement', function () use (&$alipayGlobal, $currentUrl) {
116+
routeMap($type === 'pay/agreement', function () use (&$alipayGlobal, $currentUrl) {
115117
try {
116118
session_start();
117119
$result = $alipayGlobal->payAgreement(array(
@@ -176,7 +178,7 @@
176178
}
177179
});
178180

179-
route($type === 'notify', function () use (&$alipayGlobal) {
181+
routeMap($type === 'notify', function () use (&$alipayGlobal) {
180182
try {
181183
$notify = $alipayGlobal->getNotify();
182184
// do something
@@ -187,11 +189,11 @@
187189
}
188190
});
189191

190-
route($type === 'return', function () {
192+
routeMap($type === 'return', function () {
191193
echo 'Payment or Authorization completed';
192194
});
193195

194-
route($type === 'notify/auth/auth_code', function () use (&$alipayGlobal) {
196+
routeMap($type === 'notify/auth/auth_code', function () use (&$alipayGlobal) {
195197
try {
196198
$notify = $alipayGlobal->getNotify();
197199
// do something
@@ -207,7 +209,7 @@
207209
}
208210
});
209211

210-
route($type === 'refund/refund_online', function () use (&$alipayGlobal) {
212+
routeMap($type === 'refund/refund_online', function () use (&$alipayGlobal) {
211213
try {
212214
$result = $alipayGlobal->sendRefund(array(
213215
'paymentId' => '20181129190741010007000000XXXX',

0 commit comments

Comments
 (0)