广告平台(站长使用)
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

63 rader
1.8 KiB

  1. package youlianghui
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/lib/youlianghui/md"
  5. )
  6. type ApiService struct {
  7. MemberId string `json:"member_id"`
  8. Secret string `json:"secret"`
  9. Host string `json:"host"`
  10. Header map[string]string `json:"header"`
  11. }
  12. func NewApiService(memberId, secret string) (apiService ApiService, err error) { // set方法
  13. apiService.MemberId = memberId
  14. apiService.Secret = secret
  15. apiService.Host = "https://test-api.adnet.qq.com/open/v1.1"
  16. if cfg.Prd {
  17. apiService.Host = "http://api.adnet.qq.com/open/v1.1"
  18. }
  19. apiService.Header = make(map[string]string)
  20. apiService.Header["Content-Type"] = "multipart/form-data"
  21. apiService.Header["token"] = GetToken(apiService.MemberId, apiService.Secret)
  22. return
  23. }
  24. // MediumAdd 创建媒体
  25. func (apiService *ApiService) MediumAdd(req md.MediumAdd) (appId string, err error) { // set方法
  26. url := apiService.Host + "/medium/add"
  27. if req.Affiliation == "" {
  28. req.Affiliation = "Agency" // Own:应用开发者、Agency:应用发行/代理方
  29. }
  30. params := map[string]string{
  31. "member_id": apiService.MemberId,
  32. "medium_name": req.MediumName,
  33. "industry_id_v2": req.IndustryIdV2,
  34. "os": req.Os,
  35. "affiliation": req.Affiliation,
  36. "package_name": req.PackageName,
  37. "full_package_name": req.FullPackageName,
  38. "wechat_app_id": req.WechatAppId,
  39. "package_name_wx_appid_rel": req.PackageNameWxAppidRel,
  40. "wechat_universal_link": req.WechatUniversalLink,
  41. }
  42. postBody, err := MultipartFormDataRequest(url, params, nil, apiService.Header)
  43. if err != nil {
  44. return "", err
  45. }
  46. var resp md.AgencyCreateAdunit
  47. err = json.Unmarshal(postBody, &resp)
  48. if err != nil {
  49. return
  50. }
  51. if resp.Ret != 0 {
  52. err = errors.New(resp.ErrMsg)
  53. }
  54. adUnitId = resp.AdUnitId
  55. return
  56. }