提交 78506403 authored 作者: lihaixin's avatar lihaixin

初始

上级 60e5e630
package weimob
import (
"encoding/json"
"errors"
)
func (w *weimobConfig) RightsDetial(accessToken, rightsId string) (res RightsDetialRes, err error) {
url := w.ApiUrl + "api/1_0/ec/rights/getRightsOrderDetail?accesstoken=" + accessToken
query := map[string]interface{}{"id": rightsId}
queryBody, err := json.Marshal(query)
if err != nil {
return
}
queryData := w.PostJSON(url, queryBody)
err = json.Unmarshal([]byte(queryData), &res)
return
}
//拒绝售后
func (w *weimobConfig) AfterSaleRefuse(accesstoken string, id int64, refusedReason string) (res string, err error) {
if id <= 0 {
err = errors.New("售后id不能为空")
return
}
deliveryParams := map[string]interface{}{
"id": id,
"cancelType": 2,
"refusedReason": "售后申请被拒绝",
}
if len(refusedReason) > 0 {
deliveryParams["refusedReason"] = refusedReason
}
url := w.ApiUrl + "api/1_0/ec/rights/cancelRightsOrder?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
res = w.PostJSON(url, body)
return
}
//同意售后
func (w *weimobConfig) AfterSaleAgree(accesstoken string, id, rightsType int64) (res string, err error) {
if id <= 0 {
err = errors.New("售后id不能为空")
return
}
if rightsType != 1 && rightsType != 2 && rightsType != 5 {
err = errors.New("售后id不能为空")
return
}
deliveryParams := map[string]interface{}{
"id": id,
"rightsType": rightsType,
}
url := w.ApiUrl + "api/1_0/ec/rights/agreeRightsOrder?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
res = w.PostJSON(url, body)
return
}
//商家确认收货 a
func (w *weimobConfig) ConfirmReceivedRightsGoods(accesstoken string, id int64) (res string, err error) {
if id <= 0 {
err = errors.New("售后id不能为空")
return
}
deliveryParams := map[string]interface{}{
"id": id,
}
url := w.ApiUrl + "api/1_0/ec/rights/confirmReceivedRightsGoods?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
res = w.PostJSON(url, body)
return
}
package weimob
import (
"encoding/json"
)
//获取授权店铺
func (w *weimobConfig) GetShopRefreshToken(clientId, clientSecret, redirectUri, code string) (data *ShopAccessTokenRes, err error) {
url := w.ApiUrl + "fuwu/b/oauth2/token?code=" + code + "&grant_type=authorization_code&client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=" + redirectUri
res := w.DoPost(url, map[string]interface{}{})
err = json.Unmarshal([]byte(res), &data)
return
}
//刷新店铺access_token接口
func (w *weimobConfig) GetShopAccessToken(clientId, clientSecret, refreshToken string) (data *ShopAccessTokenRes, err error) {
url := w.ApiUrl + "fuwu/b/oauth2/token?grant_type=refresh_token&client_id=" + clientId + "&client_secret=" + clientSecret + "&refresh_token=" + refreshToken
res := w.DoPost(url, map[string]interface{}{})
err = json.Unmarshal([]byte(res), &data)
return
}
package weimob
import (
"encoding/json"
)
func (w *weimobConfig) GetSkuId(accesstoken string, outerSkuCode int, storeId string) (res *GetSkuIdRes, err error) {
url := w.ApiUrl + "api/1_0/ec/singleProduct/queryProductListBySkuCode?accesstoken=" + accesstoken
data := w.DoPost(url, map[string]interface{}{"skuCode": outerSkuCode, "storeId": storeId})
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) UpdatePrice(accesstoken string, req map[string]interface{}) (res *WeimobRes, err error) {
url := w.ApiUrl + "api/1_0/ec/retailGoods/updatePrice?accesstoken=" + accesstoken
data := w.DoPost(url, req)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) UpdateStock(accesstoken string, req map[string]interface{}) (res *WeimobRes, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/updateStock?accesstoken=" + accesstoken
data := w.DoPost(url, req)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) GoodsDetail(accesstoken, goodId string) (res *WeimobGoodsDetialResult, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/queryGoodsDetail?accesstoken=" + accesstoken
body, _ := json.Marshal(map[string]string{"goodsId": goodId})
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
//查询模板
func (w *weimobConfig) FindFreightTemplateList(accesstoken string) (res *FindFreightTemplateListRes, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/findFreightTemplateList?accesstoken=" + accesstoken
data := w.DoPost(url, map[string]interface{}{})
err = json.Unmarshal([]byte(data), &res)
return
}
//查询快递
func (w *weimobConfig) FindDeliveryTypeList(accesstoken string) (res *FindDeliveryTypeListRes, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/findDeliveryTypeList?accesstoken=" + accesstoken
data := w.DoPost(url, map[string]interface{}{})
err = json.Unmarshal([]byte(data), &res)
return
}
//查询sku
func (w *weimobConfig) CategoryAttrInfo(accesstoken string, deliveryParams map[string]interface{}) (res *CategoryAttrInfoRes, err error) {
url := w.ApiUrl + "api/1_0/ec/category/queryCategoryAttrInfo?accesstoken=" + accesstoken
queryBody, err := json.Marshal(deliveryParams)
if err != nil {
return
}
queryData := w.PostJSON(url, queryBody)
err = json.Unmarshal([]byte(queryData), &res)
return
}
//添加sku
func (w *weimobConfig) AddAttributeName(accesstoken string, deliveryParams map[string]interface{}) (res *AddAttributeNameRes, err error) {
url := w.ApiUrl + "api/1_0/ec/category/addAttribute?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
//添加sku值
func (w *weimobConfig) AddAttributeValue(accesstoken string, deliveryParams map[string]interface{}) (res *AddAttributeValueRes, err error) {
url := w.ApiUrl + "api/1_0/ec/category/addAttrValue?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) Add(accesstoken string, good map[string]interface{}) (res *WeimobGoodsResult, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/addGoods?accesstoken=" + accesstoken
body, err := json.Marshal(good)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) Update(accesstoken string, good map[string]interface{}) (res *WeimobGoodsResult, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/updateGoods?accesstoken=" + accesstoken
body, err := json.Marshal(good)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) Dels(accesstoken string, goodIds []int64) (res *WeimobGoodsDelResult, err error) {
url := w.ApiUrl + "api/1_0/ec/goods/deleteGoods?accesstoken=" + accesstoken
body, _ := json.Marshal(map[string][]int64{"goodsIdList": goodIds})
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) CategoryTree(accesstoken string) (res *Result, err error) {
url := w.ApiUrl + "api/1_0/ec/category/queryCategoryTree?accesstoken=" + accesstoken
data := w.DoPost(url, map[string]interface{}{})
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) ChildrenCategory(accesstoken string, categoryId int) (res *Result, err error) {
url := w.ApiUrl + "api/1_0/ec/category/queryChildrenCategory?accesstoken=" + accesstoken
body := map[string]interface{}{
"categoryId": categoryId,
}
data, _ := json.Marshal(body)
r := w.PostJSON(url, data)
err = json.Unmarshal([]byte(r), &res)
return
}
差异被折叠。
package weimob
import (
"encoding/json"
"errors"
)
func (w *weimobConfig) OrderDetial(accesstoken, orderNo string) (res *WeimodOrderDetialRes, err error) {
if len(orderNo) <= 0 {
err = errors.New("订单号错误")
return
}
url := w.ApiUrl + "api/1_0/ec/order/queryOrderDetail?accesstoken=" + accesstoken
body, err := json.Marshal(map[string]string{"orderNo": orderNo})
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
//微店取消订单
func (w *weimobConfig) WeimobCancelOrder(accesstoken, orderNo, specificCancelReason, cancelReason string, cancelReasonId int) (res string, err error) {
if len(orderNo) <= 0 {
err = errors.New("订单号错误")
return
}
deliveryParams := map[string]interface{}{
"orderNo": orderNo,
}
if len(specificCancelReason) > 0 {
deliveryParams["specificCancelReason"] = specificCancelReason
}
if len(cancelReason) > 0 {
deliveryParams["cancelReason"] = cancelReason
}
if cancelReasonId > 0 {
deliveryParams["cancelReasonId"] = cancelReasonId
}
url := w.ApiUrl + "api/1_0/ec/order/cancelOrder?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
//微店发货接口
func (w *weimobConfig) WeimobLogisticsAddMultiPack(accesstoken string, deliveryParams map[string]interface{}) (res string, err error) {
url := w.ApiUrl + "api/1_0/ec/order/deliveryOrder?accesstoken=" + accesstoken
body, err := json.Marshal(deliveryParams)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
func (w *weimobConfig) OrderList(accesstoken string, order *WeimodOrderListReq) (res *WeimodOrderListRes, err error) {
url := w.ApiUrl + "api/1_0/ec/order/queryOrderList?accesstoken=" + accesstoken
body, err := json.Marshal(order)
if err != nil {
return
}
data := w.PostJSON(url, body)
err = json.Unmarshal([]byte(data), &res)
return
}
package weimob
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
type weimobConfig struct {
ApiUrl string
ServerName string
}
var Weimob = weimobConfig{
" you ApiUrl", //无特殊情况为 "https://dopen.weimob.com/",
"you ServerName", //项目名
}
//post json参数
func (w *weimobConfig) PostJSON(url string, data []byte) string {
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
if err != nil {
return ""
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("service_name", w.ServerName)
client := http.Client{}
resp, err := client.Do(req)
if err != nil || resp.StatusCode != 200 {
return ""
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return ""
}
return string(respBytes)
}
//Json post
func (w *weimobConfig) DoPost(url string, params map[string]interface{}) string {
data, errp := json.Marshal(params)
if errp != nil {
// logs.Log("POST/PostJSON/ERR", "error", "参数json化错误:【%v】 ", errp)
return ""
}
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
if err != nil {
return ""
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("service_name", w.ServerName)
client := http.Client{}
resp, err := client.Do(req)
if err != nil || resp.StatusCode != 200 {
return ""
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return ""
}
return string(respBytes)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论