- jd page api:GetCorporationInfo
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi"
|
"git.rosy.net.cn/baseapi/platformapi"
|
||||||
@@ -21,6 +22,48 @@ type SkuPageImg struct {
|
|||||||
Small string `json:"small"`
|
Small string `json:"small"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CorporationInfo struct {
|
||||||
|
Scope string `json:"scope"`
|
||||||
|
OperName string `json:"oper_name"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
BelongOrg string `json:"belong_org"`
|
||||||
|
CreditNo string `json:"credit_no"`
|
||||||
|
RegNo string `json:"reg_no"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
OrgNo string `json:"org_no"`
|
||||||
|
EconKind string `json:"econ_kind"`
|
||||||
|
EndDate string `json:"end_date"`
|
||||||
|
TermEnd string `json:"term_end"`
|
||||||
|
NeedID bool `json:"needID"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
Partners []struct {
|
||||||
|
IdentifyType string `json:"identify_type"`
|
||||||
|
ShouldCapiItems []interface{} `json:"should_capi_items"`
|
||||||
|
StockType string `json:"stock_type"`
|
||||||
|
IdentifyNo string `json:"identify_no"`
|
||||||
|
RealCapiItems []interface{} `json:"real_capi_items"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"partners"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
TermStart string `json:"term_start"`
|
||||||
|
AbnormalItems []interface{} `json:"abnormal_items"`
|
||||||
|
CheckDate string `json:"check_date"`
|
||||||
|
RegistCapi string `json:"regist_capi"`
|
||||||
|
StartDate string `json:"start_date"`
|
||||||
|
Changerecords []struct {
|
||||||
|
BeforeContent string `json:"before_content"`
|
||||||
|
ChangeDate string `json:"change_date"`
|
||||||
|
ChangeItem string `json:"change_item"`
|
||||||
|
AfterContent string `json:"after_content"`
|
||||||
|
} `json:"changerecords"`
|
||||||
|
Branches []interface{} `json:"branches"`
|
||||||
|
Employees []struct {
|
||||||
|
JobTitle string `json:"job_title"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"employees"`
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) SetStoreCookie(storeCookie string) {
|
func (a *API) SetStoreCookie(storeCookie string) {
|
||||||
a.locker.Lock()
|
a.locker.Lock()
|
||||||
defer a.locker.Unlock()
|
defer a.locker.Unlock()
|
||||||
@@ -33,14 +76,21 @@ func (a *API) GetStoreCookie() string {
|
|||||||
return a.storeCookie
|
return a.storeCookie
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) AccessStorePage(fullURL string) (retVal map[string]interface{}, err error) {
|
func (a *API) AccessStorePage(fullURL string, formData map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
storeCookie := a.GetStoreCookie()
|
storeCookie := a.GetStoreCookie()
|
||||||
if storeCookie == "" {
|
if storeCookie == "" {
|
||||||
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||||
}
|
}
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
func() *http.Request {
|
func() *http.Request {
|
||||||
request, _ := http.NewRequest(http.MethodGet, fullURL, nil)
|
var request *http.Request
|
||||||
|
if formData == nil {
|
||||||
|
request, _ = http.NewRequest(http.MethodGet, fullURL, nil)
|
||||||
|
} else {
|
||||||
|
request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(formData).Encode()))
|
||||||
|
request.Header.Set("charset", "UTF-8")
|
||||||
|
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -88,7 +138,7 @@ func (a *API) GetStoreOrderInfo(orderId, stationNo string) (storeOrderInfo map[s
|
|||||||
if stationNo != "" {
|
if stationNo != "" {
|
||||||
urlStr += "&stationNo=" + stationNo
|
urlStr += "&stationNo=" + stationNo
|
||||||
}
|
}
|
||||||
retVal, err := a.AccessStorePage(urlStr)
|
retVal, err := a.AccessStorePage(urlStr, nil)
|
||||||
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
|
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
|
newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
|
||||||
@@ -106,7 +156,7 @@ func (a *API) GetStoreOrderInfoList(fromTime, toTime string) (storeOrderList []m
|
|||||||
pageNo := 1
|
pageNo := 1
|
||||||
urlTemplate := "http://store.jddj.com/order/newManager/tabQuery/all?o2oOrderType=10000&pageNo=%d&pageSize=%d&orderBy=&desc=true&startTimeQuery=%s&endTimeQuery=%s&stationNo="
|
urlTemplate := "http://store.jddj.com/order/newManager/tabQuery/all?o2oOrderType=10000&pageNo=%d&pageSize=%d&orderBy=&desc=true&startTimeQuery=%s&endTimeQuery=%s&stationNo="
|
||||||
for {
|
for {
|
||||||
retVal, err := a.AccessStorePage(fmt.Sprintf(urlTemplate, pageNo, pageSize, url.QueryEscape(fromTime), url.QueryEscape(toTime)))
|
retVal, err := a.AccessStorePage(fmt.Sprintf(urlTemplate, pageNo, pageSize, url.QueryEscape(fromTime), url.QueryEscape(toTime)), nil)
|
||||||
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
|
// baseapi.SugarLogger.Debug(utils.Format4Output(retVal, false))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
|
newOrderinfoMains := retVal["newOrderinfoMains"].(map[string]interface{})
|
||||||
@@ -128,7 +178,7 @@ func (a *API) GetSkuPageInfo(skuId int64) (skuPageInfo map[string]interface{}, e
|
|||||||
"skuId": utils.Int64ToStr(skuId),
|
"skuId": utils.Int64ToStr(skuId),
|
||||||
"storeId": "0",
|
"storeId": "0",
|
||||||
}
|
}
|
||||||
skuPageInfo, err = a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?platCode=H5&functionId=product/detailV6_0&body=%s", utils.Format4Output(skuIDMap, true)))
|
skuPageInfo, err = a.AccessStorePage(fmt.Sprintf("https://daojia.jd.com/client?platCode=H5&functionId=product/detailV6_0&body=%s", utils.Format4Output(skuIDMap, true)), nil)
|
||||||
return skuPageInfo, err
|
return skuPageInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,3 +189,14 @@ func (a *API) GetSkuPageImageInfo(skuId int64) (imgList []*SkuPageImg, err error
|
|||||||
}
|
}
|
||||||
return imgList, err
|
return imgList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) GetCorporationInfo(stationNo, qualifyNumber string) (corporatonInfo *CorporationInfo, err error) {
|
||||||
|
result, err := a.AccessStorePage("https://sta-store.jddj.com/store/requestQualify.o2o", map[string]interface{}{
|
||||||
|
"stationNo": stationNo,
|
||||||
|
"qualifyNumber": qualifyNumber,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
err = utils.Map2StructByJson(result, &corporatonInfo, false)
|
||||||
|
}
|
||||||
|
return corporatonInfo, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -54,3 +54,11 @@ func TestGetSkuPageImageInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
baseapi.SugarLogger.Debug(utils.Format4Output(imgList, false))
|
baseapi.SugarLogger.Debug(utils.Format4Output(imgList, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetCorporationInfo(t *testing.T) {
|
||||||
|
imgList, err := api.GetCorporationInfo("", "915101003431062533")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
baseapi.SugarLogger.Debug(utils.Format4Output(imgList, false))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user