物料下单测试,微信发票
This commit is contained in:
@@ -29,13 +29,13 @@ const (
|
|||||||
state = "1212"
|
state = "1212"
|
||||||
orderType10 = "10" //订单号类型(10:代表ECLP订单号, 20:代表商家订单号)
|
orderType10 = "10" //订单号类型(10:代表ECLP订单号, 20:代表商家订单号)
|
||||||
orderType20 = "20"
|
orderType20 = "20"
|
||||||
|
SalePlatformSource = "6"
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
accessToken string
|
accessToken string
|
||||||
appKey string
|
appKey string
|
||||||
appSecret string
|
appSecret string
|
||||||
redirectUri string
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
config *platformapi.APIConfig
|
config *platformapi.APIConfig
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ type SearchShopStockResult struct {
|
|||||||
PageNumber string `json:"pageNumber"`
|
PageNumber string `json:"pageNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(accessToken, appKey, appSecret, redirectUri string, config ...*platformapi.APIConfig) *API {
|
func New(accessToken, appKey, appSecret string, config ...*platformapi.APIConfig) *API {
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
@@ -140,7 +140,6 @@ func New(accessToken, appKey, appSecret, redirectUri string, config ...*platform
|
|||||||
accessToken: accessToken,
|
accessToken: accessToken,
|
||||||
appKey: appKey,
|
appKey: appKey,
|
||||||
appSecret: appSecret,
|
appSecret: appSecret,
|
||||||
redirectUri: redirectUri,
|
|
||||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||||
config: &curConfig,
|
config: &curConfig,
|
||||||
}
|
}
|
||||||
@@ -177,10 +176,12 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
|||||||
params["access_token"] = a.accessToken
|
params["access_token"] = a.accessToken
|
||||||
params["app_key"] = a.appKey
|
params["app_key"] = a.appKey
|
||||||
params["timestamp"] = utils.Time2Str(time.Now())
|
params["timestamp"] = utils.Time2Str(time.Now())
|
||||||
|
params["method"] = action
|
||||||
|
params["v"] = "2.0"
|
||||||
params = utils.MergeMaps(params, bizParams)
|
params = utils.MergeMaps(params, bizParams)
|
||||||
signStr := a.signParam(params)
|
signStr := a.signParam(params)
|
||||||
params["sign"] = signStr
|
params["sign"] = signStr
|
||||||
fullURL = utils.GenerateGetURL(url, "method="+action, nil)
|
fullURL = utils.GenerateGetURL(url, "", nil)
|
||||||
}
|
}
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
func() *http.Request {
|
func() *http.Request {
|
||||||
@@ -210,22 +211,22 @@ func (a *API) AccessAPI(action string, url string, bizParams map[string]interfac
|
|||||||
|
|
||||||
//获取销售平台信息
|
//获取销售平台信息
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=947&apiName=jingdong.eclp.master.querySpSource
|
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=947&apiName=jingdong.eclp.master.querySpSource
|
||||||
func (a *API) QuerySpSource() (querySpSourceResult *QuerySpSourceResult, err error) {
|
func (a *API) QuerySpSource() (querySpSourceResult []*QuerySpSourceResult, err error) {
|
||||||
result, err := a.AccessAPI("jingdong.eclp.master.querySpSource", prodURL, nil)
|
result, err := a.AccessAPI("jingdong.eclp.master.querySpSource", prodURL, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
utils.Map2StructByJson(result, &querySpSourceResult, false)
|
utils.Map2StructByJson(result["jingdong_eclp_master_querySpSource_responce"].(map[string]interface{})["queryspsource_result"], &querySpSourceResult, false)
|
||||||
}
|
}
|
||||||
return querySpSourceResult, err
|
return querySpSourceResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//销售出库单下发
|
//销售出库单下发
|
||||||
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=928&apiName=jingdong.eclp.order.addOrder
|
//https://open.jd.com/home/home#/doc/api?apiCateId=138&apiId=928&apiName=jingdong.eclp.order.addOrder
|
||||||
func (a *API) AddOrder(addOrderParam *AddOrderParam) (addOrderResult *AddOrderResult, err error) {
|
func (a *API) AddOrder(addOrderParam *AddOrderParam) (eclpSoNo string, err error) {
|
||||||
result, err := a.AccessAPI("jingdong.eclp.order.addOrder", prodURL, utils.Struct2FlatMap(addOrderParam))
|
result, err := a.AccessAPI("jingdong.eclp.order.addOrder", prodURL, utils.Struct2FlatMap(addOrderParam))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
utils.Map2StructByJson(result, &addOrderResult, false)
|
return result["eclpSoNo"].(string), err
|
||||||
}
|
}
|
||||||
return addOrderResult, err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
//销售出库单取消
|
//销售出库单取消
|
||||||
@@ -278,32 +279,33 @@ func (a *API) SearchShopStock(searchShopStockParam *SearchShopStockParam) (searc
|
|||||||
|
|
||||||
//获取tokenCode
|
//获取tokenCode
|
||||||
//https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&state=YOUR_CUSTOM_CODE
|
//https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&state=YOUR_CUSTOM_CODE
|
||||||
func (a *API) GetTokenInfo() (code string, err error) {
|
//https://oauth.jd.com/oauth/authorize?response_type=code&client_id=YOUR_APP_KEY&redirect_uri=urn:ietf:wg:oauth:2.0:oob&state=1212
|
||||||
result, err := a.AccessAPI("authorize", prodURL2, map[string]interface{}{
|
// func (a *API) GetTokenInfo() (code string, err error) {
|
||||||
"response_type": "code",
|
// result, err := a.AccessAPI("authorize", prodURL2, map[string]interface{}{
|
||||||
"client_id": a.appKey,
|
// "response_type": "code",
|
||||||
"redirect_uri": a.redirectUri,
|
// "client_id": a.appKey,
|
||||||
"state": state,
|
// "redirect_uri": a.redirectUri,
|
||||||
})
|
// "state": state,
|
||||||
if err == nil {
|
// })
|
||||||
code = result["code"].(string)
|
// if err == nil {
|
||||||
}
|
// code = result["code"].(string)
|
||||||
return code, err
|
// }
|
||||||
}
|
// return code, err
|
||||||
|
// }
|
||||||
|
|
||||||
//获取token
|
//获取token
|
||||||
//https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=GET_CODE&state=YOUR_CUSTOM_CODE&client_secret= YOUR_APP_SECRET
|
//https://oauth.jd.com/oauth/token?grant_type=authorization_code&client_id=YOUR_APP_KEY&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=GET_CODE&state=YOUR_CUSTOM_CODE&client_secret= YOUR_APP_SECRET
|
||||||
func (a *API) GetToken() (token string, err error) {
|
// func (a *API) GetToken() (token string, err error) {
|
||||||
code, err := a.GetTokenInfo()
|
// code, err := a.GetTokenInfo()
|
||||||
result, err := a.AccessAPI("token", prodURL2, map[string]interface{}{
|
// result, err := a.AccessAPI("token", prodURL2, map[string]interface{}{
|
||||||
"grant_type": "authorization_code",
|
// "grant_type": "authorization_code",
|
||||||
"client_id": a.appKey,
|
// "client_id": a.appKey,
|
||||||
"redirect_uri": a.redirectUri,
|
// "redirect_uri": a.redirectUri,
|
||||||
"code": code,
|
// "code": code,
|
||||||
"state": state,
|
// "state": state,
|
||||||
})
|
// })
|
||||||
if err == nil {
|
// if err == nil {
|
||||||
token = result["token"].(string)
|
// token = result["token"].(string)
|
||||||
}
|
// }
|
||||||
return token, err
|
// return token, err
|
||||||
}
|
// }
|
||||||
|
|||||||
5
platformapi/weixinapi/card.go
Normal file
5
platformapi/weixinapi/card.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package weixinapi
|
||||||
|
|
||||||
|
func GetAuthUrl() {
|
||||||
|
|
||||||
|
}
|
||||||
1
platformapi/weixinapi/card_test.go
Normal file
1
platformapi/weixinapi/card_test.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package weixinapi
|
||||||
@@ -4,6 +4,9 @@ import "git.rosy.net.cn/baseapi/utils"
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
MaxRemarkByteCount = 30
|
MaxRemarkByteCount = 30
|
||||||
|
|
||||||
|
ticketType = "wx_card"
|
||||||
|
authType = 0 //Int 是 授权类型,0:开票授权,1:填写字段开票授权,2:领票授权
|
||||||
)
|
)
|
||||||
|
|
||||||
type CBUserInfo struct {
|
type CBUserInfo struct {
|
||||||
@@ -25,6 +28,13 @@ type CBUserInfo struct {
|
|||||||
QRSceneStr string `json:"qr_scene_str"`
|
QRSceneStr string `json:"qr_scene_str"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CBTicketInfo struct {
|
||||||
|
Errcode int `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
Ticket string `json:"ticket"`
|
||||||
|
ExpiresIn int `json:"expires_in"`
|
||||||
|
}
|
||||||
|
|
||||||
func (a *API) CBSetToken(newToken string) bool {
|
func (a *API) CBSetToken(newToken string) bool {
|
||||||
curToken := a.CBGetToken()
|
curToken := a.CBGetToken()
|
||||||
if curToken != newToken {
|
if curToken != newToken {
|
||||||
@@ -93,3 +103,15 @@ func (a *API) CBGetUserInfo(userOpenID string) (userInfo *CBUserInfo, err error)
|
|||||||
}
|
}
|
||||||
return userInfo, err
|
return userInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取授权页ticket
|
||||||
|
func (a *API) CBGetTicketInfo() (ticketInfo *CBTicketInfo, err error) {
|
||||||
|
bodyJson := map[string]interface{}{
|
||||||
|
"type": ticketType,
|
||||||
|
}
|
||||||
|
result, err := a.AccessAPI("cgi-bin/ticket/getticket", bodyJson, "")
|
||||||
|
if err == nil {
|
||||||
|
err = utils.Map2StructByJson(result, &ticketInfo, false)
|
||||||
|
}
|
||||||
|
return ticketInfo, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user