|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DtApp\ThinkLibrary\service\taobao; |
|
4
|
|
|
|
|
5
|
|
|
require_once __DIR__ . '/bin/TopSdk.php'; |
|
6
|
|
|
|
|
7
|
|
|
use DtApp\ThinkLibrary\Service; |
|
8
|
|
|
use TbkScInvitecodeGetRequest; |
|
9
|
|
|
use TbkScPublisherInfoGetRequest; |
|
10
|
|
|
use TbkScPublisherInfoSaveRequest; |
|
11
|
|
|
use TopClient; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* 淘宝服务 |
|
15
|
|
|
* Class TaoBaoService |
|
16
|
|
|
* @package DtApp\ThinkLibrary\service\taobao |
|
17
|
|
|
*/ |
|
18
|
|
|
class TaoBaoService extends Service |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* TOP分配给应用的 |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $app_key, $app_secret = ""; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* 需要发送的的参数 |
|
28
|
|
|
* @var |
|
29
|
|
|
*/ |
|
30
|
|
|
private $param; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* 响应内容 |
|
34
|
|
|
* @var |
|
35
|
|
|
*/ |
|
36
|
|
|
private $output; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* 配置应用的AppKey |
|
40
|
|
|
* @param string $appKey |
|
41
|
|
|
* @return $this |
|
42
|
|
|
*/ |
|
43
|
|
|
public function appKey(string $appKey): self |
|
44
|
|
|
{ |
|
45
|
|
|
$this->app_key = $appKey; |
|
46
|
|
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* 应用AppSecret |
|
51
|
|
|
* @param string $appSecret |
|
52
|
|
|
* @return $this |
|
53
|
|
|
*/ |
|
54
|
|
|
public function appSecret(string $appSecret): self |
|
55
|
|
|
{ |
|
56
|
|
|
$this->app_secret = $appSecret; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* 请求参数 |
|
62
|
|
|
* @param array $param |
|
63
|
|
|
* @return $this |
|
64
|
|
|
*/ |
|
65
|
|
|
public function param(array $param): self |
|
66
|
|
|
{ |
|
67
|
|
|
$this->param = $param; |
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* ( 淘宝客-公用-私域用户备案 ) |
|
73
|
|
|
* 通过入参渠道管理或会员运营管理的邀请码,生成渠道id或会员运营id,完成渠道或会员的备案。 |
|
74
|
|
|
* https://open.taobao.com/api.htm?docId=37988&docType=2&scopeId=14474 |
|
75
|
|
|
* @param $sessionKey |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
|
|
public function tbkScPublisherInfoSave($sessionKey): self |
|
79
|
|
|
{ |
|
80
|
|
|
$c = new TopClient(); |
|
81
|
|
|
$c->appkey = $this->app_key; |
|
82
|
|
|
$c->secretKey = $this->app_secret; |
|
83
|
|
|
$req = new TbkScPublisherInfoSaveRequest(); |
|
84
|
|
|
if (isset($this->param['relation_from'])) { |
|
85
|
|
|
$req->setRelationFrom($this->param['relation_from']); |
|
86
|
|
|
} |
|
87
|
|
|
if (isset($this->param['offline_scene'])) { |
|
88
|
|
|
$req->setOfflineScene($this->param['offline_scene']); |
|
89
|
|
|
} |
|
90
|
|
|
if (isset($this->param['online_scene'])) { |
|
91
|
|
|
$req->setOnlineScene($this->param['online_scene']); |
|
92
|
|
|
} |
|
93
|
|
|
if (isset($this->param['inviter_code'])) { |
|
94
|
|
|
$req->setInviterCode($this->param['inviter_code']); |
|
95
|
|
|
} |
|
96
|
|
|
if (isset($this->param['info_type'])) { |
|
97
|
|
|
$req->setInfoType($this->param['info_type']); |
|
98
|
|
|
} |
|
99
|
|
|
if (isset($this->param['note'])) { |
|
100
|
|
|
$req->setNote($this->param['note']); |
|
101
|
|
|
} |
|
102
|
|
|
if (isset($this->param['register_info'])) { |
|
103
|
|
|
$req->setRegisterInfo($this->param['register_info']); |
|
104
|
|
|
} |
|
105
|
|
|
$this->output = $c->execute($req, $sessionKey); |
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* ( 淘宝客-公用-私域用户备案信息查询 ) |
|
111
|
|
|
* 查询已生成的渠道id或会员运营id的相关信息。 |
|
112
|
|
|
* https://open.taobao.com/api.htm?docId=37989&docType=2&scopeId=14474 |
|
113
|
|
|
* @param $sessionKey |
|
114
|
|
|
* @return $this |
|
115
|
|
|
*/ |
|
116
|
|
|
public function tbkScPublisherInfoGet($sessionKey): self |
|
117
|
|
|
{ |
|
118
|
|
|
$c = new TopClient(); |
|
119
|
|
|
$c->appkey = $this->app_key; |
|
120
|
|
|
$c->secretKey = $this->app_secret; |
|
121
|
|
|
$req = new TbkScPublisherInfoGetRequest(); |
|
122
|
|
|
if (isset($this->param['info_type'])) { |
|
123
|
|
|
$req->setInfoType($this->param['info_type']); |
|
124
|
|
|
} |
|
125
|
|
|
if (isset($this->param['relation_id'])) { |
|
126
|
|
|
$req->setRelationId($this->param['relation_id']); |
|
127
|
|
|
} |
|
128
|
|
|
if (isset($this->param['page_no'])) { |
|
129
|
|
|
$req->setPageNo($this->param['page_no']); |
|
130
|
|
|
} |
|
131
|
|
|
if (isset($this->param['page_size'])) { |
|
132
|
|
|
$req->setPageSize($this->param['page_size']); |
|
133
|
|
|
} |
|
134
|
|
|
if (isset($this->param['relation_app'])) { |
|
135
|
|
|
$req->setRelationApp($this->param['relation_app']); |
|
136
|
|
|
} |
|
137
|
|
|
if (isset($this->param['special_id'])) { |
|
138
|
|
|
$req->setSpecialId($this->param['special_id']); |
|
139
|
|
|
} |
|
140
|
|
|
if (isset($this->param['external_id'])) { |
|
141
|
|
|
$req->setExternalId($this->param['external_id']); |
|
142
|
|
|
} |
|
143
|
|
|
$this->output = $c->execute($req, $sessionKey); |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* ( 淘宝客-公用-私域用户邀请码生成 ) |
|
149
|
|
|
* 私域用户管理(即渠道管理或会员运营管理)功能中,通过此API可生成淘宝客自身的邀请码。 |
|
150
|
|
|
* https://open.taobao.com/api.htm?docId=38046&docType=2&scopeId=14474 |
|
151
|
|
|
* @param $sessionKey |
|
152
|
|
|
* @return $this |
|
153
|
|
|
*/ |
|
154
|
|
|
public function tbkScInvitecodeGet($sessionKey): self |
|
155
|
|
|
{ |
|
156
|
|
|
$c = new TopClient(); |
|
157
|
|
|
$c->appkey = $this->app_key; |
|
158
|
|
|
$c->secretKey = $this->app_secret; |
|
159
|
|
|
$req = new TbkScInvitecodeGetRequest(); |
|
160
|
|
|
if (isset($this->param['relation_id'])) { |
|
161
|
|
|
$req->setRelationId($this->param['relation_id']); |
|
162
|
|
|
} |
|
163
|
|
|
if (isset($this->param['relation_app'])) { |
|
164
|
|
|
$req->setRelationApp($this->param['relation_app']); |
|
165
|
|
|
} |
|
166
|
|
|
if (isset($this->param['code_type'])) { |
|
167
|
|
|
$req->setCodeType($this->param['code_type']); |
|
168
|
|
|
} |
|
169
|
|
|
$this->output = $c->execute($req, $sessionKey); |
|
170
|
|
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* 返回Array |
|
175
|
|
|
* @return array|mixed |
|
176
|
|
|
*/ |
|
177
|
|
|
public function toArray() |
|
178
|
|
|
{ |
|
179
|
|
|
if (isset($this->output['error_response'])) { |
|
180
|
|
|
// 错误 |
|
181
|
|
|
if (is_array($this->output)) { |
|
182
|
|
|
return $this->output; |
|
183
|
|
|
} |
|
184
|
|
|
if (is_object($this->output)) { |
|
185
|
|
|
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE); |
|
186
|
|
|
} |
|
187
|
|
|
return json_decode($this->output, true); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
// 正常 |
|
191
|
|
|
if (is_array($this->output)) { |
|
192
|
|
|
return $this->output; |
|
193
|
|
|
} |
|
194
|
|
|
if (is_object($this->output)) { |
|
195
|
|
|
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE); |
|
196
|
|
|
} |
|
197
|
|
|
$this->output = json_decode($this->output, true); |
|
198
|
|
|
return $this->output; |
|
199
|
|
|
} |
|
200
|
|
|
} |