广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api.go 1.8 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }