package youlianghui import ( "applet/app/cfg" "applet/app/lib/youlianghui/md" ) type ApiService struct { MemberId string `json:"member_id"` Secret string `json:"secret"` Host string `json:"host"` Header map[string]string `json:"header"` } func NewApiService(memberId, secret string) (apiService ApiService, err error) { // set方法 apiService.MemberId = memberId apiService.Secret = secret apiService.Host = "https://test-api.adnet.qq.com/open/v1.1" if cfg.Prd { apiService.Host = "http://api.adnet.qq.com/open/v1.1" } apiService.Header = make(map[string]string) apiService.Header["Content-Type"] = "multipart/form-data" apiService.Header["token"] = GetToken(apiService.MemberId, apiService.Secret) return } // MediumAdd 创建媒体 func (apiService *ApiService) MediumAdd(req md.MediumAdd) (appId string, err error) { // set方法 url := apiService.Host + "/medium/add" if req.Affiliation == "" { req.Affiliation = "Agency" // Own:应用开发者、Agency:应用发行/代理方 } params := map[string]string{ "member_id": apiService.MemberId, "medium_name": req.MediumName, "industry_id_v2": req.IndustryIdV2, "os": req.Os, "affiliation": req.Affiliation, "package_name": req.PackageName, "full_package_name": req.FullPackageName, "wechat_app_id": req.WechatAppId, "package_name_wx_appid_rel": req.PackageNameWxAppidRel, "wechat_universal_link": req.WechatUniversalLink, } postBody, err := MultipartFormDataRequest(url, params, nil, apiService.Header) if err != nil { return "", err } var resp md.AgencyCreateAdunit err = json.Unmarshal(postBody, &resp) if err != nil { return } if resp.Ret != 0 { err = errors.New(resp.ErrMsg) } adUnitId = resp.AdUnitId return }