Skip to content

Commit fe03e1b

Browse files
committed
- 优化淘宝官方SDK
1 parent f71c302 commit fe03e1b

File tree

682 files changed

+49038
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

682 files changed

+49038
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v6.0.126 / 2020-11-19
2+
- 优化淘宝官方SDK
3+
14
## v6.0.125 / 2020-11-19
25
- 优化淘宝服务协议
36

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
},
4848
"autoload": {
4949
"files": [
50-
"src/common.php"
50+
"src/common.php",
51+
"src/service/taobao/bin/TopSdk.php"
5152
],
5253
"psr-4": {
5354
"DtApp\\ThinkLibrary\\": "src"

src/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* 定义当前版本
2727
*/
28-
const VERSION = '6.0.125';
28+
const VERSION = '6.0.126';
2929

3030
if (!function_exists('get_ip_info')) {
3131
/**

src/service/pinduoduo/bin/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## 拼多多开放平台PHP版本的SDK
2+
- 环境要求:php 5.5版本及以上,使用composer包管理工具
3+
- 执行一下 composer install 安装命令
4+
- 该SDK使用 composer 对src下面的代码进行命名空间自动导入,namespace 自动导入的规则是[psr4 规范](https://www.php-fig.org/psr/psr-4/)
5+
- 该SDK共有2个文件夹,src文件夹下面是sdk主功能文件夹。example文件夹下面是所有接口的demo,作为测试样例参考。
6+
7+
## src文件夹下面文件功能说明
8+
* PopAccessTokenClient 类
9+
- generate : 根据从授权后回调地址那里拿到的code 值,然后去服务器获取access_token和refresh_token以及过期时间等值
10+
- refresh:由于access_token时效性是24小时,refresh_token的时效性是30天,所以,当acces_token过期后,利用refresh_token进行重新获取access_token
11+
* PopHttpClient 类
12+
- syncInvoke : 把接口名称 type 以及各自接口对应的业务参数,access_token(如果需要授权)传给这个接口即可获取到对应接口的返回值。
13+
* Api/Request
14+
- 这个文件夹下面存放所有接口的自定义请求Request类
15+
* Common
16+
- 这个文件夹下面存放所有的公共功能类
17+
* Token
18+
- 这个文件夹下面存放获取和刷新token相关接口的request
19+
20+
## example 文件夹说明
21+
22+
* AccessToken.php 获取 access_token 的示例代码
23+
* Config_sample.php 使用的时候文件重命名为Config.php,替换文件里面的配置信息
24+
* PddXXXX.php 针对某个特定的接口对应的示例代码
25+
26+
## 使用示例
27+
### 用户授权
28+
```php
29+
$clientId = "your app clientId";
30+
$clientSecret = "your app clientSecret";
31+
$refreshToken = "your app refreshToken";
32+
$code = "your code";
33+
34+
35+
$accessTokenClient = new PopAccessTokenClient($clientId,$clientSecret);
36+
37+
38+
// 生成AccessToken
39+
40+
$result = $accessTokenClient->generate($code);
41+
$result = json_encode($result->getContent(),JSON_UNESCAPED_UNICODE);
42+
echo $result;
43+
44+
45+
46+
// 刷新AccessToken
47+
48+
$result = $accessTokenClient->refresh($refreshToken);
49+
$result = json_encode($result->getContent(),JSON_UNESCAPED_UNICODE);
50+
echo $result;
51+
52+
```
53+
54+
### 访问接口(以获取商品详情接口为例):
55+
56+
```php
57+
58+
$clientId = "your app clientId";
59+
$clientSecret = "your app clientSecret";
60+
$pid = "your pid";
61+
62+
//创建client客户端
63+
$client = new PopHttpClient($clientId, $clientSecret);
64+
65+
//创建请求对象
66+
$request = new PddDdkGoodsDetailRequest();
67+
$request->setGoodsIdList(array(6730722720));
68+
$request->setPid($pid);
69+
$request->setCustomParameters('str');
70+
$request->setZsDuoId(1111111);
71+
$request->setPlanType(1);
72+
73+
//发起接口请求
74+
try{
75+
$response = $client->syncInvoke($request);
76+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
77+
echo $e->getMessage();
78+
exit;
79+
}
80+
81+
$content = $response->getContent();
82+
83+
//判断是否异常
84+
if(isset($content['error_response'])){
85+
echo "异常返回";
86+
}
87+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
88+
89+
```
90+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"require": {
3+
"php": "^5.5|^7.0",
4+
"ext-curl": "*",
5+
"ext-json": "*"
6+
},
7+
"repositories": {
8+
"packagist": {
9+
"type": "composer",
10+
"url": "https://mirrors.aliyun.com/composer/"
11+
}
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"Com\\Pdd\\Pop\\Sdk\\": "src/"
16+
}
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
//多多客授权:https://jinbao.pinduoduo.com/open.html?client_id=$client_id&response_type=code&redirect_uri=https://hanshan.com
3+
require_once dirname(__FILE__).'/Config.php';
4+
require_once dirname(__FILE__)."/../vendor/autoload.php";
5+
6+
use Com\Pdd\Pop\Sdk\PopAccessTokenClient;
7+
8+
9+
$clientId = Config::$clientId;
10+
$clientSecret = Config::$clientSecret;
11+
$client = new PopAccessTokenClient($clientId, $clientSecret);
12+
13+
$code = Config::$code;//通过授权获取
14+
$result = $client->generate($code);
15+
$result = json_encode($result->getContent(),JSON_UNESCAPED_UNICODE);
16+
echo $result;
17+
die();
18+
19+
$result = $client->refresh(Config::$refreshToken);
20+
$result = json_encode($result->getContent(),JSON_UNESCAPED_UNICODE);
21+
echo $result;
22+
23+
24+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class Config
4+
{
5+
static public $clientId = "Your client id";
6+
static public $clientSecret = "Your client secret";
7+
static public $accessToken ="Your access token";
8+
static public $refreshToken = "Your refresh token";
9+
static public $code = "Your code";
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.advertiser.open.account
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserOpenAccountRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiAdvertiserOpenAccountRequest();
13+
14+
try{
15+
$response = $client->syncInvoke($request);
16+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
17+
echo $e->getMessage();
18+
exit;
19+
}
20+
$content = $response->getContent();
21+
if(isset($content['error_response'])){
22+
echo "异常返回";
23+
}
24+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.advertiser.query.account.balance
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountBalanceRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiAdvertiserQueryAccountBalanceRequest();
13+
14+
try{
15+
$response = $client->syncInvoke($request);
16+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
17+
echo $e->getMessage();
18+
exit;
19+
}
20+
$content = $response->getContent();
21+
if(isset($content['error_response'])){
22+
echo "异常返回";
23+
}
24+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.advertiser.query.account.info
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountInfoRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiAdvertiserQueryAccountInfoRequest();
13+
14+
try{
15+
$response = $client->syncInvoke($request);
16+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
17+
echo $e->getMessage();
18+
exit;
19+
}
20+
$content = $response->getContent();
21+
if(isset($content['error_response'])){
22+
echo "异常返回";
23+
}
24+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.advertiser.query.detail
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryDetailRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiAdvertiserQueryDetailRequest();
13+
14+
try{
15+
$response = $client->syncInvoke($request);
16+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
17+
echo $e->getMessage();
18+
exit;
19+
}
20+
$content = $response->getContent();
21+
if(isset($content['error_response'])){
22+
echo "异常返回";
23+
}
24+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.goods.query.gallery.images
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryGalleryImagesRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiGoodsQueryGalleryImagesRequest();
13+
14+
$request->setGoodsId(1);
15+
try{
16+
$response = $client->syncInvoke($request);
17+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
18+
echo $e->getMessage();
19+
exit;
20+
}
21+
$content = $response->getContent();
22+
if(isset($content['error_response'])){
23+
echo "异常返回";
24+
}
25+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.goods.query.long.images
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryLongImagesRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiGoodsQueryLongImagesRequest();
13+
14+
$request->setGoodsId(1);
15+
try{
16+
$response = $client->syncInvoke($request);
17+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
18+
echo $e->getMessage();
19+
exit;
20+
}
21+
$content = $response->getContent();
22+
if(isset($content['error_response'])){
23+
echo "异常返回";
24+
}
25+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.goods.query.page
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryPageRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiGoodsQueryPageRequest();
13+
14+
$request->setGoodsName('str');
15+
$request->setPageNumber(1);
16+
$request->setPageSize(1);
17+
$request->setPlanId(1);
18+
try{
19+
$response = $client->syncInvoke($request);
20+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
21+
echo $e->getMessage();
22+
exit;
23+
}
24+
$content = $response->getContent();
25+
if(isset($content['error_response'])){
26+
echo "异常返回";
27+
}
28+
echo json_encode($content,JSON_UNESCAPED_UNICODE);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* 示例接口名称:pdd.ad.api.keyword.create
4+
*/
5+
require_once dirname(__FILE__).'/Config.php';
6+
require_once dirname(__FILE__)."/../vendor/autoload.php";
7+
8+
use Com\Pdd\Pop\Sdk\PopHttpClient;
9+
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordCreateRequest;
10+
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
11+
12+
$request = new PddAdApiKeywordCreateRequest();
13+
14+
$request->setAdId(1);
15+
$request->setKeywordList();
16+
try{
17+
$response = $client->syncInvoke($request);
18+
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
19+
echo $e->getMessage();
20+
exit;
21+
}
22+
$content = $response->getContent();
23+
if(isset($content['error_response'])){
24+
echo "异常返回";
25+
}
26+
echo json_encode($content,JSON_UNESCAPED_UNICODE);

0 commit comments

Comments
 (0)