-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathuser.php
More file actions
88 lines (81 loc) · 2.2 KB
/
Copy pathuser.php
File metadata and controls
88 lines (81 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Ping++ Server SDK
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可根据自己网站需求按照技术文档编写, 并非一定要使用该代码。
* 该代码仅供学习和研究 Ping++ SDK 使用,仅供参考。
*/
require dirname(__DIR__) . '/init.php';
// 示例配置文件,测试请根据文件注释修改其配置
require 'config.php';
\Pingpp\Pingpp::setApiKey(API_KEY); // 设置 API Key
\Pingpp\Pingpp::setAppId(APP_ID); // 设置 APP ID
\Pingpp\Pingpp::setPrivateKeyPath(__DIR__ . '/your_rsa_private_key.pem'); // 设置私钥
// 创建 user 对象
try {
$user = \Pingpp\User::create(
[
'id' => uniqid('uid'), // 用户 ID ,由商户提供
]
);
echo $user;
} catch (\Pingpp\Error\Base $e) {
if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus());
echo $e->getHttpBody();
} else {
echo $e->getMessage();
}
}
exit;
// 查询 user 对象
$uid = 'uid598ae2dabbe71';
try {
$user = \Pingpp\User::retrieve($uid);
echo $user;
} catch (\Pingpp\Error\Base $e) {
if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus());
echo $e->getHttpBody();
} else {
echo $e->getMessage();
}
}
exit;
// 更新 user 对象
$uid = 'uid582d35283f628';
try {
$user = \Pingpp\User::update($uid, [
'address' => 'China',
'name' => strval(mt_rand(1000, 9999)),
'metadata' => [
'key' => 'value'
],
]);
echo $user;
} catch (\Pingpp\Error\Base $e) {
if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus());
echo $e->getHttpBody();
} else {
echo $e->getMessage();
}
}
exit;
// 查询列表
try {
$params = [
'page' => 1,
'per_page' => 10,
];
$users = \Pingpp\User::all($params);
echo $users;
} catch (\Pingpp\Error\Base $e) {
if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus());
echo $e->getHttpBody();
} else {
echo $e->getMessage();
}
}
exit;