获取商品列表-已登的店铺,删除商品-已登的店铺,新增商品等接口,版本1.0
This commit is contained in:
parent
3c0c91bf3b
commit
aed65dfb31
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,7 +4,7 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
#*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
|
||||
BIN
dll/kongfz.dll
Normal file
BIN
dll/kongfz.dll
Normal file
Binary file not shown.
24
dll/kongfz.h
24
dll/kongfz.h
@ -92,6 +92,30 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// 登录(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutLogin(char* username, char* password);
|
||||
|
||||
// 获取用户信息(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutGetUserMsg(char* token);
|
||||
|
||||
// 获取商品模版(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutGetGoodsTplMsg(char* token, char* itemId, char* proxy);
|
||||
|
||||
// 获取商品列表-已登的店铺(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutGetGoodsListMsgFromSelfShop(char* token, char* proxy, char* itemSn, char* priceMin, char* priceMax, int startCreateTime, int endCreateTime, char* requestType, int isItemSnEqual, int page, int size);
|
||||
|
||||
// 删除商品-已登的店铺(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutDelGoodsFromSelfShop(char* token, char* proxy, char* itemId);
|
||||
|
||||
// 新增商品(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutAddGoods(char* token, char* proxy, char* formData);
|
||||
|
||||
// 获取商品图片(带有Out的都非官方标准接口)
|
||||
//
|
||||
extern __declspec(dllexport) char* OutGetImageByIsbn(char* token, char* isbn, char* proxy, int isLiveImage, int isReturnMsg);
|
||||
|
||||
BIN
dll/proxyConfig.dll
Normal file
BIN
dll/proxyConfig.dll
Normal file
Binary file not shown.
BIN
dll/test.dll
Normal file
BIN
dll/test.dll
Normal file
Binary file not shown.
BIN
dll/xkongfz.dll
Normal file
BIN
dll/xkongfz.dll
Normal file
Binary file not shown.
101
main.go
101
main.go
@ -519,7 +519,69 @@ func outGetGoodsListMsgFromSelfShop(token string, proxy string, itemSn string, p
|
||||
if err := json.Unmarshal([]byte(body), &data); err != nil {
|
||||
return nil, fmt.Errorf("解析JSON失败: %w", err)
|
||||
}
|
||||
if val, ok := data["status"]; ok && val == 1 {
|
||||
if _, ok := data["status"]; ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf("API返回错误: %+v", data)
|
||||
}
|
||||
|
||||
// 删除商品-已登的店铺(带有Out的都非官方标准接口)
|
||||
func outDelGoodsFromSelfShop(token, proxy, itemId string) (map[string]interface{}, error) {
|
||||
if token == "" {
|
||||
return nil, fmt.Errorf("请先登录获取Token")
|
||||
}
|
||||
url := "https://seller.kongfz.com/pc-gw/book-manage-service/client/pc/goods/quickUpdate"
|
||||
formData := map[string]string{
|
||||
"itemId": itemId,
|
||||
"updateType": "delete",
|
||||
"value": "1",
|
||||
}
|
||||
request := gorequest.New()
|
||||
if proxy != "" {
|
||||
request.Proxy(proxy)
|
||||
}
|
||||
resp, body, errs := request.Post(url).
|
||||
Set("Cookie", fmt.Sprintf("PHPSESSID=%s", token)).
|
||||
Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36").
|
||||
Set("Accept", "application/json, text/plain, */*").
|
||||
Send(formData).
|
||||
Timeout(15 * time.Second).
|
||||
End()
|
||||
if errs != nil {
|
||||
// 检查是否是代理相关错误
|
||||
var isProxyError bool
|
||||
var errorDetails []string
|
||||
for _, e := range errs {
|
||||
errorStr := e.Error()
|
||||
errorDetails = append(errorDetails, errorStr)
|
||||
if strings.Contains(errorStr, "Proxy Authentication Required") ||
|
||||
strings.Contains(errorStr, "connectex: A connection attempt failed") ||
|
||||
strings.Contains(errorStr, "connectex: No connection could be made") ||
|
||||
strings.Contains(errorStr, "proxyconnect tcp") ||
|
||||
strings.Contains(errorStr, "timeout") ||
|
||||
strings.Contains(errorStr, "connection refused") {
|
||||
isProxyError = true
|
||||
}
|
||||
}
|
||||
log.Printf("[ERROR] 请求错误详情: %v", errorDetails)
|
||||
if isProxyError {
|
||||
// 处理代理失败
|
||||
return nil, fmt.Errorf("代理连接失败")
|
||||
}
|
||||
return nil, fmt.Errorf("查询请求失败: %v", errs)
|
||||
}
|
||||
//检查HTTP状态码
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("HTTP错误: %s", resp.Status)
|
||||
}
|
||||
var data map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(body), &data); err != nil {
|
||||
return nil, fmt.Errorf("解析JSON失败: %w", err)
|
||||
}
|
||||
if status, ok := data["status"].(bool); ok && status {
|
||||
return data, nil
|
||||
}
|
||||
if status, ok := data["status"].(float64); ok && status == 1 {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf("API返回错误: %+v", data)
|
||||
@ -527,6 +589,9 @@ func outGetGoodsListMsgFromSelfShop(token string, proxy string, itemSn string, p
|
||||
|
||||
// 新增商品(带有Out的都非官方标准接口)
|
||||
func outAddGoods(token, proxy, formData string) (map[string]interface{}, error) {
|
||||
if token == "" {
|
||||
return nil, fmt.Errorf("请先登录获取Token")
|
||||
}
|
||||
url := "https://seller.kongfz.com/pc/itemInfo/add"
|
||||
request := gorequest.New()
|
||||
if proxy != "" {
|
||||
@ -2782,6 +2847,40 @@ func OutGetGoodsListMsgFromSelfShop(token, proxy, itemSn, priceMin, priceMax *C.
|
||||
return C.CString(string(jsonData))
|
||||
}
|
||||
|
||||
// 删除商品-已登的店铺(带有Out的都非官方标准接口)
|
||||
//
|
||||
//export OutDelGoodsFromSelfShop
|
||||
func OutDelGoodsFromSelfShop(token, proxy, itemId *C.char) *C.char {
|
||||
goToken := C.GoString(token)
|
||||
goProxy := C.GoString(proxy)
|
||||
goItemId := C.GoString(itemId)
|
||||
info, err := outDelGoodsFromSelfShop(goToken, goProxy, goItemId)
|
||||
var apiResponse APIResponse
|
||||
if err != nil {
|
||||
apiResponse = APIResponse{
|
||||
Success: false,
|
||||
Message: err.Error(),
|
||||
}
|
||||
} else {
|
||||
apiResponse = APIResponse{
|
||||
Success: true,
|
||||
Data: info,
|
||||
}
|
||||
}
|
||||
// 转换为JSON字符串
|
||||
jsonData, marshalErr := json.Marshal(apiResponse)
|
||||
if marshalErr != nil {
|
||||
// 如果JSON序列化失败,返回错误信息
|
||||
apiResponse = APIResponse{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("JSON序列化失败: %v", marshalErr),
|
||||
}
|
||||
errorJson, _ := json.Marshal(apiResponse)
|
||||
return C.CString(string(errorJson))
|
||||
}
|
||||
return C.CString(string(jsonData))
|
||||
}
|
||||
|
||||
// 新增商品(带有Out的都非官方标准接口)
|
||||
//
|
||||
//export OutAddGoods
|
||||
|
||||
164
zjdydll.go
164
zjdydll.go
@ -417,6 +417,115 @@ func (m *DLLManager) OutLogin(username, password string) (string, error) {
|
||||
return string(resultBytes), nil
|
||||
}
|
||||
|
||||
// 获取 OutGetUserMsg
|
||||
func (m *DLLManager) OutGetUserMsg(token string) (string, error) {
|
||||
// 获取函数
|
||||
proc, err := m.dll.FindProc("OutGetUserMsg")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("找不到函数 %s: %v", "OutGetUserMsg", err)
|
||||
}
|
||||
// 转换参数
|
||||
tokenPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(token)))
|
||||
// 调用函数
|
||||
ret, _, err := proc.Call(tokenPtr)
|
||||
if ret == 0 {
|
||||
return "", fmt.Errorf("DLL调用失败: %v", err)
|
||||
}
|
||||
|
||||
// 将C字符串转换为Go字符串
|
||||
var resultBytes []byte
|
||||
for i := 0; ; i++ {
|
||||
if *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))) == 0 {
|
||||
break
|
||||
}
|
||||
resultBytes = append(resultBytes, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))))
|
||||
}
|
||||
|
||||
// 释放内存(假设DLL提供了FreeMemory函数)
|
||||
findProc, err := m.dll.FindProc("FreeString")
|
||||
if findProc != nil {
|
||||
findProc.Call(ret)
|
||||
}
|
||||
return string(resultBytes), nil
|
||||
}
|
||||
|
||||
// 获取 OutGetGoodsTplMsg
|
||||
func (m *DLLManager) OutGetGoodsTplMsg(token, itemId, proxy string) (string, error) {
|
||||
// 获取函数
|
||||
proc, err := m.dll.FindProc("OutGetGoodsTplMsg")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("找不到函数 %s: %v", "OutGetGoodsTplMsg", err)
|
||||
}
|
||||
// 转换参数
|
||||
tokenPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(token)))
|
||||
itemIdPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(itemId)))
|
||||
proxyPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(proxy)))
|
||||
// 调用函数
|
||||
ret, _, err := proc.Call(tokenPtr, itemIdPtr, proxyPtr)
|
||||
if ret == 0 {
|
||||
return "", fmt.Errorf("DLL调用失败: %v", err)
|
||||
}
|
||||
|
||||
// 将C字符串转换为Go字符串
|
||||
var resultBytes []byte
|
||||
for i := 0; ; i++ {
|
||||
if *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))) == 0 {
|
||||
break
|
||||
}
|
||||
resultBytes = append(resultBytes, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))))
|
||||
}
|
||||
|
||||
// 释放内存(假设DLL提供了FreeMemory函数)
|
||||
findProc, err := m.dll.FindProc("FreeString")
|
||||
if findProc != nil {
|
||||
findProc.Call(ret)
|
||||
}
|
||||
return string(resultBytes), nil
|
||||
}
|
||||
|
||||
// 获取 OutGetGoodsListMsgFromSelfShop
|
||||
func (m *DLLManager) OutGetGoodsListMsgFromSelfShop(token string, proxy string, itemSn string, priceMin string, priceMax string, startCreateTime int,
|
||||
endCreateTime int, requestType string, isItemSnEqual int, page int, size int) (string, error) {
|
||||
// 获取函数
|
||||
proc, err := m.dll.FindProc("OutGetGoodsListMsgFromSelfShop")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("找不到函数 %s: %v", "OutGetGoodsListMsgFromSelfShop", err)
|
||||
}
|
||||
// 转换参数
|
||||
tokenPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(token)))
|
||||
proxyPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(proxy)))
|
||||
itemSnPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(itemSn)))
|
||||
priceMinPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(priceMin)))
|
||||
priceMaxPtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(priceMax)))
|
||||
startCreateTimePtr := uintptr(startCreateTime)
|
||||
endCreateTimePtr := uintptr(endCreateTime)
|
||||
requestTypePtr := uintptr(unsafe.Pointer(syscall.StringBytePtr(requestType)))
|
||||
isItemSnEqualPtr := uintptr(isItemSnEqual)
|
||||
pagePtr := uintptr(page)
|
||||
sizePtr := uintptr(size)
|
||||
// 调用函数
|
||||
ret, _, err := proc.Call(tokenPtr, proxyPtr, itemSnPtr, priceMinPtr, priceMaxPtr, startCreateTimePtr, endCreateTimePtr, requestTypePtr, isItemSnEqualPtr, pagePtr, sizePtr)
|
||||
if ret == 0 {
|
||||
return "", fmt.Errorf("DLL调用失败: %v", err)
|
||||
}
|
||||
|
||||
// 将C字符串转换为Go字符串
|
||||
var resultBytes []byte
|
||||
for i := 0; ; i++ {
|
||||
if *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))) == 0 {
|
||||
break
|
||||
}
|
||||
resultBytes = append(resultBytes, *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(ret)) + uintptr(i))))
|
||||
}
|
||||
|
||||
// 释放内存(假设DLL提供了FreeMemory函数)
|
||||
findProc, err := m.dll.FindProc("FreeString")
|
||||
if findProc != nil {
|
||||
findProc.Call(ret)
|
||||
}
|
||||
return string(resultBytes), nil
|
||||
}
|
||||
|
||||
// 获取 OutGetImageByIsbn
|
||||
func (m *DLLManager) OutGetImageByIsbn(token string, isbn string, proxy string, isLiveImage bool, isReturnMsg bool) (string, error) {
|
||||
// 获取函数
|
||||
@ -793,7 +902,7 @@ func main() {
|
||||
|
||||
func handleGetKFZShopBookInfo(w http.ResponseWriter, r *http.Request) {
|
||||
// 加载DLL
|
||||
manager, err := NewDLLManager("dll/xkongfz.dll")
|
||||
manager, err := NewDLLManager("dll/kongfz.dll")
|
||||
if err != nil {
|
||||
fmt.Printf("初始化DLL管理器失败: %v", err)
|
||||
}
|
||||
@ -833,24 +942,55 @@ func handleGetKFZShopBookInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
login, err := outLogin("15140030829", "cuiyang")
|
||||
// 获取代理信息
|
||||
typeManager, err := proxyTypeManager("CALF_ELEPHANT_PROXY", "1297757178467602432", "QgQBvP7f", "")
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
}
|
||||
fmt.Println(login)
|
||||
fmt.Println(typeManager)
|
||||
|
||||
msg, err := outGetGoodsTplMsg(login, "1181761", "")
|
||||
user, err := manager.OutLogin("18904056801", "Long6166@@")
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
}
|
||||
fmt.Println(user)
|
||||
|
||||
var data APIResponse
|
||||
if err := json.Unmarshal([]byte(user), &data); err != nil {
|
||||
log.Printf("[ERROR] 解析第 %d 页失败: %v", data, err)
|
||||
}
|
||||
var token string
|
||||
// 从 Data 中提取 token
|
||||
if dataMap, ok := data.Data.(map[string]interface{}); ok {
|
||||
if tk, exists := dataMap["token"]; exists {
|
||||
fmt.Println("Token:", tk)
|
||||
token = tk.(string)
|
||||
// Token: d322c80960ab6722922912dd2ce219d4b4099d54
|
||||
} else {
|
||||
fmt.Println("Token 不存在")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Data 格式不正确")
|
||||
}
|
||||
fmt.Println(token)
|
||||
|
||||
msg, err := manager.OutGetUserMsg(token)
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
}
|
||||
fmt.Println(msg)
|
||||
|
||||
//// 获取代理信息
|
||||
//typeManager, err := proxyTypeManager("CALF_ELEPHANT_PROXY", "1297757178467602432", "QgQBvP7f", "")
|
||||
//if err != nil {
|
||||
// fmt.Printf(err.Error())
|
||||
//}
|
||||
//fmt.Println(typeManager)
|
||||
tplMsg, err := manager.OutGetGoodsTplMsg(token, "9142583516", "")
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
}
|
||||
fmt.Println(tplMsg)
|
||||
|
||||
shop, err := manager.OutGetGoodsListMsgFromSelfShop(token, "", "", "", "", 0, 0, "allUnSold", 0, 1, 10)
|
||||
if err != nil {
|
||||
fmt.Printf(err.Error())
|
||||
}
|
||||
fmt.Println(shop)
|
||||
|
||||
//// 获取cookie
|
||||
//cookie, err := loginCookie()
|
||||
@ -955,6 +1095,10 @@ func handleGetKFZShopBookInfo(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func manegiyoutGetGoodsListMsgFromSelfShop() {
|
||||
|
||||
}
|
||||
|
||||
// 发送错误响应
|
||||
func sendErrorResponse(w http.ResponseWriter, statusCode int, message string) {
|
||||
response := APIResp{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user