pdd.dll 使用教程
1.创建DLL工具实例
加载DLL文件
// PddDLL 拼多多工具DLL结构
type pddDLL struct {
dll *syscall.DLL
pddGoodsOuterCatMappingGet *syscall.Proc // 类目预测
freeCString *syscall.Proc // 释放C字符串
}
// 初始化pddDLL
func InitPddDLL() (*pddDLL, error) {
dllPath := filepath.Join("dll", "pdd.dll")
if _, err := os.Stat(dllPath); os.IsNotExist(err) {
return nil, fmt.Errorf("pdd DLL 不存在: %s", dllPath)
}
if dll, err := syscall.LoadDLL(dllPath); err != nil {
return nil, fmt.Errorf("加载pdd DLL 失败: %s", err)
} else {
return &pddDLL{
dll: dll,
pddGoodsOuterCatMappingGet: dll.MustFindProc("PddGoodsOuterCatMappingGet"),
freeCString: dll.MustFindProc("FreeCString"),
}, nil
}
}
dll, err := InitPddDLL()
获取C字符串
// cStr 获取C字符串
func (m *pddDLL) cStr(p uintptr) string {
if p == 0 {
return ""
}
b := []byte{}
for i := uintptr(0); ; i++ {
c := *(*byte)(unsafe.Pointer(p + i))
if c == 0 {
break
}
b = append(b, c)
}
s := string(b)
if m.freeCString != nil {
m.freeCString.Call(p)
}
return s
}
2. 使用dll函数示例
// 类目预测
func (m *pddDLL) PddGoodsOuterCatMappingGet(clientId, clientSecret, accessToken,
outerCatId, outerCatName, outerGoodsName string) (string, error) {
proc, err := m.dll.FindProc("PddGoodsOuterCatMappingGet")
if err != nil {
return "", fmt.Errorf("找不到函数 PddGoodsOuterCatMappingGet: %v", err)
}
clientIdPtr, _ := syscall.BytePtrFromString(clientId)
clientSecretPtr, _ := syscall.BytePtrFromString(clientSecret)
accessTokenPtr, _ := syscall.BytePtrFromString(accessToken)
outerCatIdPtr, _ := syscall.BytePtrFromString(outerCatId)
outerCatNamePtr, _ := syscall.BytePtrFromString(outerCatName)
outerGoodsNamePtr, _ := syscall.BytePtrFromString(outerGoodsName)
resultPtr, _, _ := proc.Call(
uintptr(unsafe.Pointer(clientIdPtr)),
uintptr(unsafe.Pointer(clientSecretPtr)),
uintptr(unsafe.Pointer(accessTokenPtr)),
uintptr(unsafe.Pointer(outerCatIdPtr)),
uintptr(unsafe.Pointer(outerCatNamePtr)),
uintptr(unsafe.Pointer(outerGoodsNamePtr)),
)
result := m.cStr(resultPtr)
return result, nil
}
接口详情
1. 类目预测--PddGoodsOuterCatMappingGet
请求信息
dll.PddGoodsOuterCatMappingGet(clientId, clientSecret, accessToken,
outerCatId, outerCatName, outerGoodsName)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| outerCatId |
string |
是 |
外部平台类目ID |
| outerCatName |
string |
是 |
外部平台类目名称 |
| outerGoodsName |
string |
是 |
外部商品名称 |
响应示例
{
"outer_cat_mapping_get_response": {
"cat_id2": 16028,
"cat_id3": 16031,
"cat_id1": 15543,
"request_id": "17666480184871649",
"cat_id4": 0
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
2. 快递公司查看--PddLogisticsCompaniesGet
请求信息
dll.PddLogisticsCompaniesGet(clientId, clientSecret)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
响应示例
{
"logistics_companies_get_response": {
"logistics_companies": [
{
"available": 1,
"code": "SF",
"id": 1,
"logistics_company": "顺丰速运"
},
{
"available": 1,
"code": "STO",
"id": 2,
"logistics_company": "申通快递"
}
]
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
3. erp打单信息同步--PddErpOrderSync
请求信息
dll.PddErpOrderSync(clientId, clientSecret, accessToken, logisticsId,
orderSn, orderState, waybillNo)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| logisticsId |
string |
是 |
物流公司ID |
| orderSn |
string |
是 |
拼多多订单号 |
| orderState |
string |
是 |
订单状态 |
| waybillNo |
string |
是 |
运单号 |
响应示例
{
"erp_order_sync_response": {
"is_success": true,
"request_id": "17666480184871650"
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
4. 拼多多订单同步--PddOrderSynchronization
请求信息
dll.PddOrderSynchronization(clientId, clientSecret, accessToken, logisticsCompany, logisticsId,
orderSn, orderState, waybillNo)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| logisticsCompany |
string |
是 |
物流公司名称 |
| logisticsId |
string |
是 |
物流公司ID |
| orderSn |
string |
是 |
拼多多订单号 |
| orderState |
string |
是 |
订单状态 |
| waybillNo |
string |
是 |
运单号 |
响应示例
{
"erp_order_sync_response": {
"is_success": true,
"request_id": "17666480184871651"
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
5. 商品图片上传接口--PddGoodsImgUpload
请求信息
dll.PddGoodsImgUpload(clientId, clientSecret, accessToken, filePath)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| filePath |
string |
是 |
图片文件路径 |
响应示例
{
"goods_img_upload_response": {
"image_url": "http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg",
"request_id": "17666480184871652"
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
6. 商品新增接口--PddGoodsAdd
请求信息
dll.PddGoodsAdd(clientId, clientSecret, accessToken, goodsAddJson)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| goodsAddJson |
string |
是 |
商品信息JSON字符串 |
商品信息JSON结构示例
{
"goods_name": "测试商品",
"goods_desc": "商品描述",
"cat_id": 20111,
"goods_type": 1,
"market_price": 9900,
"is_folt": false,
"is_pre_sale": false,
"is_refundable": true,
"shipment_limit_second": 86400,
"cost_template_id": 10001,
"image_url": "http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg",
"carousel_gallery": [
"http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg"
],
"detail_gallery": [
"http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg"
],
"sku_list": [
{
"out_sku_sn": "SKU001",
"price": 8900,
"quantity": 100,
"spec_id_list": "1001:10001",
"sku_properties": [
{
"ref_pid": 1001,
"value": "红色",
"vid": 10001,
"punit": "个"
}
],
"is_onsale": 1,
"limit_quantity": 10,
"multi_price": 8500,
"thumb_url": "http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg",
"weight": 500
}
]
}
响应示例
{
"goods_add_response": {
"goods_id": 123456789,
"goods_name": "测试商品",
"goods_sn": "G202501200001",
"request_id": "17666480184871653"
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
7. 联合拼多多图片上传的商品新增--SelfPddGoodsAdd
请求信息
dll.SelfPddGoodsAdd(clientId, clientSecret, accessToken, filePath, goodsAddJson)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| filePath |
string |
是 |
图片文件路径 |
| goodsAddJson |
string |
是 |
商品信息JSON字符串(不需包含image_url) |
接口说明
此接口为组合接口,内部执行以下步骤:
1.上传商品主图文件到拼多多服务器
2.获取图片URL并自动填充到商品信息中
3.调用商品新增接口创建商品
商品信息JSON结构示例
{
"goods_name": "测试商品",
"goods_desc": "商品描述",
"cat_id": 20111,
"goods_type": 1,
"market_price": 9900,
"is_folt": false,
"is_pre_sale": false,
"is_refundable": true,
"shipment_limit_second": 86400,
"cost_template_id": 10001,
"image_url": "",
"carousel_gallery": [
"http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg"
],
"detail_gallery": [
"http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg"
],
"sku_list": [
{
"out_sku_sn": "SKU001",
"price": 8900,
"quantity": 100,
"spec_id_list": "1001:10001",
"sku_properties": [
{
"ref_pid": 1001,
"value": "红色",
"vid": 10001,
"punit": "个"
}
],
"is_onsale": 1,
"limit_quantity": 10,
"multi_price": 8500,
"thumb_url": "http://oms-imageimg.pinduoduo.com/upload/2025/01/20/e9a8c1b6e1a84f1d8d7c3a8b9e2f5c7d.jpg",
"weight": 500
}
]
}
响应示例
{
"goods_add_response": {
"goods_id": 123456790,
"goods_name": "测试商品",
"goods_sn": "G202501200002",
"request_id": "17666480184871654"
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}
8. 批量数据解密脱敏接口--PddOpenDecryptMaskBatch
请求信息
dll.PddOpenDecryptMaskBatch(clientId, clientSecret, accessToken, reqJson)
请求参数
| 参数名 |
类型 |
必填 |
说明 |
| clientId |
string |
是 |
拼多多开放平台ClientID |
| clientSecret |
string |
是 |
拼多多开放平台ClientSecret |
| accessToken |
string |
是 |
授权令牌 |
| reqJson |
string |
是 |
信息JSON字符串 |
信息JSON结构示例
[
{
"data_tag": "251229-272441044622514",
"encrypted_data": "~AgAAAAPlscEH0psOJAEXpTdsLOWvDJ9bB7IEjIoqNfiDhhJR9NHOxsdZ+PEFluSSCngCikoDU+CP/sSXZJ92ic7+PdNlJNLA7g/6VUMDWF6RvjW9IeRN+lKNarsjWDQR~0~"
}
]
响应示例
{
"open_decrypt_mask_batch_response": {
"data_decrypt_list": [
{
"data_tag": "str",
"data_type": 0,
"decrypted_data": "str",
"encrypted_data": "str",
"error_code": 0,
"error_msg": "str"
}
]
}
}
错误响应示例
{
"error_response": {
"error_msg": "公共参数错误:type",
"sub_msg": "",
"sub_code": null,
"error_code": 10001,
"request_id": "15440104776643887"
}
}