diff --git a/platformapi/dadaapi/dadaapi.go b/platformapi/dadaapi/dadaapi.go index 13bda249..2812e84e 100644 --- a/platformapi/dadaapi/dadaapi.go +++ b/platformapi/dadaapi/dadaapi.go @@ -93,7 +93,7 @@ func (a *API) signParams(mapData map[string]interface{}) string { return fmt.Sprintf("%X", md5.Sum([]byte(finalStr))) } -func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *ResponseResult, err error) { +func (a *API) AccessAPI(action string, params interface{}) (retVal *ResponseResult, err error) { params2 := make(map[string]interface{}) params2["app_key"] = a.appKey diff --git a/platformapi/dadaapi/shop.go b/platformapi/dadaapi/shop.go new file mode 100644 index 00000000..d423f38f --- /dev/null +++ b/platformapi/dadaapi/shop.go @@ -0,0 +1,78 @@ +package dadaapi + +import "git.rosy.net.cn/baseapi/utils" + +const ( + BusinessTypeSnack = 1 + BusinessTypeDrink = 2 + BusinessTypeFlower = 3 + BusinessTypePrintTicket = 8 + BusinessTypeConvStore = 9 + BusinessTypeFruitVegetable = 13 + BusinessTypeCityEComm = 19 + BusinessTypeMedicine = 20 + BusinessTypeCake = 21 + BusinessTypeWine = 24 + BusinessTypeSmallware = 25 + BusinessTypeClothing = 26 + BusinessTypeCarPart = 27 + BusinessTypeDigital = 28 + BusinessTypeCray = 29 + BusinessTypeOther = -5 +) + +func (a *API) ShopDetail(originShopID string) (shopDetail map[string]interface{}, err error) { + params := map[string]interface{}{ + "origin_shop_id": originShopID, + } + result, err := a.AccessAPI("api/shop/detail", params) + if err != nil { + return nil, err + } + return result.Result.(map[string]interface{}), nil +} + +func (a *API) ShopAdd(originShopID, stationName string, business int, cityName, areaName, stationAddress string, lng, lat float64, contactName, phone string, addParams map[string]interface{}) (outOriginShopID string, err error) { + params := map[string]interface{}{ + "station_name": stationName, + "business": business, + "city_name": cityName, + "area_name": areaName, + "station_address": stationAddress, + "lng": lng, + "lat": lat, + "contact_name": contactName, + "phone": phone, + } + if originShopID != "" { + params["origin_shop_id"] = originShopID + } + if addParams != nil { + params = utils.MergeMaps(params, addParams) + } + successList, _, err := a.BatchShopAdd([]map[string]interface{}{params}) + if err != nil { + return "", err + } + return utils.Interface2String(successList[0]["originShopId"]), nil +} + +func (a *API) BatchShopAdd(shopInfoList []map[string]interface{}) (successList, failedList []map[string]interface{}, err error) { + result, err := a.AccessAPI("api/shop/add", shopInfoList) + if err != nil { + return nil, nil, err + } + mapResult := result.Result.(map[string]interface{}) + if successList2 := mapResult["successList"]; successList2 != nil { + successList = utils.Slice2MapSlice(successList2.([]interface{})) + } + if failedList2 := mapResult["failedList"]; failedList2 != nil { + failedList = utils.Slice2MapSlice(failedList2.([]interface{})) + } + return successList, failedList, nil +} + +func (a *API) ShopUpdate(originShopID string, shopInfo map[string]interface{}) (err error) { + _, err = a.AccessAPI("api/shop/update", utils.MergeMaps(utils.Params2Map("origin_shop_id", originShopID), shopInfo)) + return err +} diff --git a/platformapi/dadaapi/shop_test.go b/platformapi/dadaapi/shop_test.go new file mode 100644 index 00000000..2d2be3c9 --- /dev/null +++ b/platformapi/dadaapi/shop_test.go @@ -0,0 +1,24 @@ +package dadaapi + +import ( + "testing" + + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/utils" +) + +func TestShopDetail(t *testing.T) { + result, err := dadaapi.ShopDetail("100119") + if err != nil { + t.Fatal(err) + } + baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) +} + +func TestShopAddl(t *testing.T) { + result, err := dadaapi.ShopAdd("18180948107", "京西大本营", BusinessTypeFruitVegetable, "成都市", "金牛区", "西南交通大学科技大厦二楼", 104.056844, 30.695151, "徐先生", "18180948107", nil) + if err != nil { + t.Fatal(err) + } + baseapi.SugarLogger.Debug(result) +} diff --git a/platformapi/weixinapi/weixinapi_test.go b/platformapi/weixinapi/weixinapi_test.go index 312c0ed8..57b8e912 100644 --- a/platformapi/weixinapi/weixinapi_test.go +++ b/platformapi/weixinapi/weixinapi_test.go @@ -42,8 +42,14 @@ func TestRefreshToken(t *testing.T) { } func TestMessageTemplateSend(t *testing.T) { - weixinapi.SetToken("14_waQJKNzZi_tNpDRyR0YsnOs-HpHVG3svnktqjlU-NE9aimGo65rpfp0YDyX6AXJ5j3smiFJt0T0JUZQ18wbD8C9limQNbptPtNUfALLf8KheVPevwMldU2UPukcXWLaAAAEDS") - err := weixinapi.MessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", "_DtNGwmOeR6TkkTVUblxLIlkV2MAPOX57TkvfdqG6nY", "http://www.163.com", nil, map[string]interface{}{ + // "oYN_usk0AeGc_C6VEZfmFQP5VHMQ": 1, // 周小扬 + // "oYN_ust9hXKEvEv0X6Mq6nlAWs_E": 1, // me + // "oYN_usvnObzrPweIgHTad9-uMf78": 1, // 老赵 + weixinapi.SetToken("17_HUkrxPrmSWDb-zuV1g9ioYj_MvHST2aGZZ58iX-g5JFiiV4vFJxQS8SvNlhHNh2HtT7aQGC3Lxozw43l-1lojMVu-6nYqqW-h2SKVxwHUvfYn5BJ6vqzQ9uU-da9u4KIazdq-ImOibw-G6pENNCfAFAIIX") + err := weixinapi.MessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", "_DtNGwmOeR6TkkTVUblxLIlkV2MAPOX57TkvfdqG6nY", "", map[string]interface{}{ + "appid": "wx4b5930c13f8b1170", + "pagepath": "pages/order-manager/main", + }, map[string]interface{}{ "first": "first", "Day": "Day", "orderId": "orderId",