广告平台(站长使用)
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.

hdl_set_center.go 31 KiB

3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
2 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. package hdl
  2. import (
  3. "applet/app/cfg"
  4. implement2 "applet/app/db/implement"
  5. "applet/app/e"
  6. "applet/app/enum"
  7. "applet/app/lib/validate"
  8. "applet/app/lib/wechat"
  9. md2 "applet/app/lib/wechat/md"
  10. "applet/app/md"
  11. "applet/app/svc"
  12. "applet/app/utils"
  13. db "code.fnuoos.com/zhimeng/model.git/src"
  14. "code.fnuoos.com/zhimeng/model.git/src/super/implement"
  15. "code.fnuoos.com/zhimeng/model.git/src/super/model"
  16. "encoding/json"
  17. "github.com/gin-gonic/gin"
  18. "strings"
  19. "time"
  20. )
  21. // SetOss
  22. // @Summary oss设置
  23. // @Tags 设置中心-基础设置
  24. // @Description 基础设置-oss设置
  25. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  26. // @Accept json
  27. // @Produce json
  28. // @Param args body md.SetOssReq true "请求参数"
  29. // @Success 200 {string} "success"
  30. // @Failure 400 {object} md.Response "具体错误"
  31. // @Router /api/setCenter/basic/setOss [POST]
  32. func SetOss(c *gin.Context) {
  33. var req md.SetOssReq
  34. err := c.ShouldBindJSON(&req)
  35. if err != nil {
  36. err = validate.HandleValidateErr(err)
  37. err1 := err.(e.E)
  38. e.OutErr(c, err1.Code, err1.Error())
  39. return
  40. }
  41. masterId := svc.GetMasterId(c)
  42. engine := db.DBs[masterId]
  43. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  44. sysCfgDb.SysCfgUpdate(enum.FileAccessKey, req.FileAccessKey)
  45. sysCfgDb.SysCfgUpdate(enum.FileSecretKey, req.FileSecretKey)
  46. sysCfgDb.SysCfgUpdate(enum.FileBucketHost, req.FileBucketHost)
  47. sysCfgDb.SysCfgUpdate(enum.FileBucketRegion, req.FileBucketRegion)
  48. sysCfgDb.SysCfgUpdate(enum.FileBucket, req.FileBucket)
  49. svc.ClearRedis(c, masterId, enum.FileAccessKey)
  50. svc.ClearRedis(c, masterId, enum.FileSecretKey)
  51. svc.ClearRedis(c, masterId, enum.FileBucketHost)
  52. svc.ClearRedis(c, masterId, enum.FileBucketRegion)
  53. svc.ClearRedis(c, masterId, enum.FileBucket)
  54. svc.ClearAllRedis(c, masterId)
  55. e.OutSuc(c, "success", nil)
  56. return
  57. }
  58. // GetOss
  59. // @Summary oss获取
  60. // @Tags 设置中心-基础设置
  61. // @Description 基础设置-oss获取
  62. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  63. // @Accept json
  64. // @Produce json
  65. // @Success 200 {object} md.SetOssResp
  66. // @Failure 400 {object} md.Response "具体错误"
  67. // @Router /api/setCenter/basic/getOss [GET]
  68. func GetOss(c *gin.Context) {
  69. masterId := svc.GetMasterId(c)
  70. engine := db.DBs[masterId]
  71. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  72. res := sysCfgDb.SysCfgFindWithDb(enum.FileAccessKey, enum.FileSecretKey, enum.FileBucketHost, enum.FileBucketRegion, enum.FileBucket)
  73. e.OutSuc(c, md.SetOssResp{
  74. Data: md.SetOssReq{
  75. FileAccessKey: res[enum.FileAccessKey],
  76. FileSecretKey: res[enum.FileSecretKey],
  77. FileBucketHost: res[enum.FileBucketHost],
  78. FileBucketRegion: res[enum.FileBucketRegion],
  79. FileBucket: res[enum.FileBucket],
  80. },
  81. QiNiuBucketRegionList: md.QiNiuBucketRegionList,
  82. }, nil)
  83. return
  84. }
  85. // WxOpenSet
  86. // @Summary 微信三方应用设置
  87. // @Tags 设置中心-基础设置
  88. // @Description 基础设置-微信三方应用设置
  89. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  90. // @Accept json
  91. // @Produce json
  92. // @Param args body md.WxOpenSetReq true "请求参数"
  93. // @Success 200 {string} "success"
  94. // @Failure 400 {object} md.Response "具体错误"
  95. // @Router /api/setCenter/basic/wxOpenSet [POST]
  96. func WxOpenSet(c *gin.Context) {
  97. var req md.WxOpenSetReq
  98. err := c.ShouldBindJSON(&req)
  99. if err != nil {
  100. err = validate.HandleValidateErr(err)
  101. err1 := err.(e.E)
  102. e.OutErr(c, err1.Code, err1.Error())
  103. return
  104. }
  105. masterId := svc.GetMasterId(c)
  106. // 1、查找对应 wx_open_third_party_app_list 记录
  107. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  108. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  109. if err != nil {
  110. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  111. return
  112. }
  113. if UserWxAppletList == nil {
  114. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  115. Uuid: utils.StrToInt(masterId),
  116. Token: req.Token,
  117. AesKey: req.AesKey,
  118. Appid: req.Appid,
  119. AppSecret: req.AppSecret,
  120. ComponentVerifyTicket: "",
  121. ComponentAccessToken: "",
  122. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  123. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  124. }
  125. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  126. if err != nil {
  127. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  128. return
  129. }
  130. } else {
  131. UserWxAppletList.Token = req.Token
  132. UserWxAppletList.AesKey = req.AesKey
  133. UserWxAppletList.Appid = req.Appid
  134. UserWxAppletList.AppSecret = req.AppSecret
  135. _, err = wxOpenThirdPartyAppListDb.UpdateWxOpenThirdPartyAppList(UserWxAppletList,
  136. "token", "aes_key", "appid", "app_secret")
  137. if err != nil {
  138. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  139. return
  140. }
  141. }
  142. e.OutSuc(c, "success", nil)
  143. return
  144. }
  145. // WxOpenGet
  146. // @Summary 微信三方应用获取
  147. // @Tags 设置中心-基础设置
  148. // @Description 基础设置-微信三方应用获取
  149. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  150. // @Accept json
  151. // @Produce json
  152. // @Success 200 {object} md.WxOpenGetResp
  153. // @Failure 400 {object} md.Response "具体错误"
  154. // @Router /api/setCenter/basic/wxOpenGet [GET]
  155. func WxOpenGet(c *gin.Context) {
  156. masterId := svc.GetMasterId(c)
  157. // 1、查找对应 wx_open_third_party_app_list 记录
  158. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  159. UserWxAppletList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  160. if err != nil {
  161. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  162. return
  163. }
  164. if UserWxAppletList == nil {
  165. UserWxAppletList = &model.WxOpenThirdPartyAppList{
  166. Uuid: utils.StrToInt(masterId),
  167. Token: "",
  168. AesKey: "",
  169. Appid: "",
  170. AppSecret: "",
  171. ComponentVerifyTicket: "",
  172. ComponentAccessToken: "",
  173. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  174. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  175. }
  176. _, err = wxOpenThirdPartyAppListDb.WxOpenThirdPartyAppListInsert(UserWxAppletList)
  177. if err != nil {
  178. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  179. return
  180. }
  181. }
  182. sysCfgDb := implement2.NewSysCfgDb(db.Db, "")
  183. res := sysCfgDb.SysCfgFindWithDb(enum.WxOpenAppletServerDomain, enum.WxOpenAuthorizationEventReceivingConfiguration,
  184. enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization, enum.WxOpenMessageAndEventReceptionConfiguration, enum.WxOpenWhiteListIp)
  185. e.OutSuc(c, md.WxOpenGetResp{
  186. Token: UserWxAppletList.Token,
  187. AesKey: UserWxAppletList.AesKey,
  188. Appid: UserWxAppletList.Appid,
  189. AppSecret: UserWxAppletList.AppSecret,
  190. WxOpenAppletServerDomain: res[enum.WxOpenAppletServerDomain],
  191. WxOpenAuthorizationEventReceivingConfiguration: res[enum.WxOpenAuthorizationEventReceivingConfiguration],
  192. WxOpenDomainOfTheInitiatingPageForLoginAuthorization: res[enum.WxOpenDomainOfTheInitiatingPageForLoginAuthorization],
  193. WxOpenMessageAndEventReceptionConfiguration: res[enum.WxOpenMessageAndEventReceptionConfiguration],
  194. WxOpenWhiteListIp: res[enum.WxOpenWhiteListIp],
  195. }, nil)
  196. return
  197. }
  198. type WxOpenThirdPartyAppList struct {
  199. Id int `json:"id" xorm:"not null pk autoincr unique(IDX_UUID_TYPE) INT(11)"`
  200. Uuid int `json:"uuid" xorm:"not null comment('站长id') index unique(IDX_UUID_TYPE) INT(10)"`
  201. Token string `json:"token" xorm:"not null default '' comment('消息校验Token') VARCHAR(255)"`
  202. AesKey string `json:"aes_key" xorm:"not null default '' comment('消息加解密Key') VARCHAR(255)"`
  203. Appid string `json:"appid" xorm:"not null default '' comment('appid') CHAR(50)"`
  204. AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"`
  205. ComponentVerifyTicket string `json:"component_verify_ticket" xorm:"not null default '' comment('验证票据') VARCHAR(255)"`
  206. ComponentAccessToken string `json:"component_access_token" xorm:"not null default '' comment('接口令牌') VARCHAR(255)"`
  207. CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  208. UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  209. }
  210. // AppletList
  211. // @Summary 列表
  212. // @Tags 设置中心-小程序设置
  213. // @Description 小程序设置-列表
  214. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  215. // @Accept json
  216. // @Produce json
  217. // @Success 200 {object} WxOpenThirdPartyAppList
  218. // @Failure 400 {object} md.Response "具体错误"
  219. // @Router /api/setCenter/applet/list [GET]
  220. func AppletList(c *gin.Context) {
  221. masterId := svc.GetMasterId(c)
  222. // 1、查找对应 user_wx_applet_list 记录
  223. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  224. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  225. if err != nil {
  226. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  227. return
  228. }
  229. e.OutSuc(c, UserWxAppletList, nil)
  230. return
  231. }
  232. // AppletAdd
  233. // @Summary 新增
  234. // @Tags 设置中心-小程序设置
  235. // @Description 小程序设置-新增
  236. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  237. // @Accept json
  238. // @Produce json
  239. // @Param args body md.AppletAddReq true "请求参数"
  240. // @Success 200 {string} "success"
  241. // @Failure 400 {object} md.Response "具体错误"
  242. // @Router /api/setCenter/applet/add [POST]
  243. func AppletAdd(c *gin.Context) {
  244. var req md.AppletAddReq
  245. err := c.ShouldBindJSON(&req)
  246. if err != nil {
  247. err = validate.HandleValidateErr(err)
  248. err1 := err.(e.E)
  249. e.OutErr(c, err1.Code, err1.Error())
  250. return
  251. }
  252. masterId := svc.GetMasterId(c)
  253. // 1、查找对应 user_wx_applet_list 记录
  254. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  255. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  256. if err != nil {
  257. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  258. return
  259. }
  260. if UserWxAppletList != nil {
  261. e.OutErr(c, e.ERR, "当前仅支持单个小程序")
  262. return
  263. }
  264. _, err = userWxAppletListDb.UserWxAppletListInsert(&model.UserWxAppletList{
  265. Name: req.Name,
  266. Logo: req.Logo,
  267. Appid: req.Appid,
  268. OriginalId: req.OriginalId,
  269. AuthorizerRefreshToken: "",
  270. IsAuth: 0,
  271. Uuid: masterId,
  272. CreateAt: time.Now().Format("2006-01-02 15:04:05"),
  273. UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
  274. })
  275. if err != nil {
  276. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  277. return
  278. }
  279. e.OutSuc(c, "success", nil)
  280. return
  281. }
  282. // AppletUpdate
  283. // @Summary 更新
  284. // @Tags 设置中心-小程序设置
  285. // @Description 小程序设置-更新
  286. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  287. // @Accept json
  288. // @Produce json
  289. // @Param args body md.AppletUpdateReq true "请求参数"
  290. // @Success 200 {string} "success"
  291. // @Failure 400 {object} md.Response "具体错误"
  292. // @Router /api/setCenter/applet/update [POST]
  293. func AppletUpdate(c *gin.Context) {
  294. var req md.AppletUpdateReq
  295. err := c.ShouldBindJSON(&req)
  296. if err != nil {
  297. err = validate.HandleValidateErr(err)
  298. err1 := err.(e.E)
  299. e.OutErr(c, err1.Code, err1.Error())
  300. return
  301. }
  302. masterId := svc.GetMasterId(c)
  303. // 1、查找对应 user_wx_applet_list 记录
  304. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  305. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  306. if err != nil {
  307. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  308. return
  309. }
  310. if UserWxAppletList == nil {
  311. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  312. return
  313. }
  314. UserWxAppletList.Logo = req.Logo
  315. UserWxAppletList.Name = req.Name
  316. _, err = userWxAppletListDb.UpdateUserWxAppletList(UserWxAppletList, "logo", "name")
  317. if err != nil {
  318. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  319. return
  320. }
  321. e.OutSuc(c, "success", nil)
  322. return
  323. }
  324. // AppletDelete
  325. // @Summary 删除
  326. // @Tags 设置中心-小程序设置
  327. // @Description 小程序设置-删除
  328. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  329. // @Accept json
  330. // @Produce json
  331. // @Success 200 {string} "success"
  332. // @Failure 400 {object} md.Response "具体错误"
  333. // @Router /v1/banner/delete/{$id} [DELETE]
  334. func AppletDelete(c *gin.Context) {
  335. id := c.Param("id")
  336. masterId := svc.GetMasterId(c)
  337. // 1、查找对应 user_wx_applet_list 记录
  338. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  339. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  340. if err != nil {
  341. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  342. return
  343. }
  344. if UserWxAppletList == nil {
  345. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  346. return
  347. }
  348. _, err = userWxAppletListDb.UserWxAppletListDelete(id)
  349. if err != nil {
  350. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  351. return
  352. }
  353. e.OutSuc(c, "success", nil)
  354. return
  355. }
  356. // AppletAuthorize
  357. // @Summary 设置中心-基础设置-微信三方应用获取
  358. // @Tags 设置中心
  359. // @Description 设置中心-基础设置
  360. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  361. // @Accept json
  362. // @Produce json
  363. // @Success 200 {string} "微信授权界面url"
  364. // @Failure 400 {object} md.Response "具体错误"
  365. // @Router /api/setCenter/applet/authorize [GET]
  366. func AppletAuthorize(c *gin.Context) {
  367. masterId := svc.GetMasterId(c)
  368. url := "http://super.advertisement.dengbiao.top/api/wxOpen/getPreAuthCode?master_id=" + masterId
  369. if cfg.Prd {
  370. url = "http://ad.zhios.cn/api/wxOpen/getPreAuthCode?master_id=" + masterId
  371. }
  372. e.OutSuc(c, map[string]string{
  373. "url": url,
  374. }, nil)
  375. return
  376. }
  377. // AppletUnauthorized
  378. // @Summary 设置中心-基础设置-微信三方应用获取
  379. // @Tags 设置中心
  380. // @Description 设置中心-基础设置
  381. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  382. // @Accept json
  383. // @Produce json
  384. // @Success 200 {string} "success"
  385. // @Failure 400 {object} md.Response "具体错误"
  386. // @Router /api/setCenter/applet/unauthorized [GET]
  387. func AppletUnauthorized(c *gin.Context) {
  388. appId := c.DefaultQuery("app_id", "")
  389. masterId := svc.GetMasterId(c)
  390. // 1、查找对应 user_wx_applet_list 记录
  391. userWxAppletListDb := implement.NewUserWxAppletListDb(db.Db)
  392. UserWxAppletList, err := userWxAppletListDb.GetUserWxAppletList(masterId)
  393. if err != nil {
  394. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  395. return
  396. }
  397. if UserWxAppletList == nil {
  398. e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
  399. return
  400. }
  401. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  402. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  403. if err != nil {
  404. e.OutErr(c, e.ERR, err.Error())
  405. return
  406. }
  407. if wxOpenThirdPartyAppList == nil {
  408. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  409. return
  410. }
  411. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  412. if err != nil {
  413. e.OutErr(c, e.ERR, err.Error())
  414. return
  415. }
  416. err = wxApiService.DelAuthorize(appId)
  417. if err != nil {
  418. e.OutErr(c, e.ERR, err.Error())
  419. return
  420. }
  421. e.OutSuc(c, "success", nil)
  422. return
  423. }
  424. // ShareIndex
  425. // @Summary 邀请链接
  426. // @Tags 设置中心-邀请链接
  427. // @Description 邀请链接界面接口
  428. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  429. // @Accept json
  430. // @Produce json
  431. // @Success 200 {object} md.ShareIndexResp
  432. // @Failure 400 {object} md.Response "具体错误"
  433. // @Router /api/setCenter/share/index [GET]
  434. func ShareIndex(c *gin.Context) {
  435. masterId := svc.GetMasterId(c)
  436. agent := new(model.UserAppDomain)
  437. _, err := db.Db.Where("type =?", "agent").And("uuid =?", masterId).And("is_ssl =1").Get(agent)
  438. if err != nil {
  439. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  440. return
  441. }
  442. medium := new(model.UserAppDomain)
  443. _, err = db.Db.Where("type =?", "medium").And("uuid =?", masterId).And("is_ssl =1").Get(medium)
  444. if err != nil {
  445. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  446. return
  447. }
  448. agentDomain := ""
  449. if agent != nil {
  450. agentDomain = agent.Domain
  451. }
  452. mediumDomain := ""
  453. if medium != nil {
  454. mediumDomain = medium.Domain
  455. }
  456. e.OutSuc(c, md.ShareIndexResp{
  457. MasterId: masterId,
  458. AgentDomain: agentDomain,
  459. MediumDomain: mediumDomain,
  460. }, nil)
  461. return
  462. }
  463. // SetMob
  464. // @Summary mob设置
  465. // @Tags 设置中心-基础设置
  466. // @Description 基础设置-mob设置
  467. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  468. // @Accept json
  469. // @Produce json
  470. // @Param args body md.SetMobReq true "请求参数"
  471. // @Success 200 {string} "success"
  472. // @Failure 400 {object} md.Response "具体错误"
  473. // @Router /api/setCenter/basic/setMob [POST]
  474. func SetMob(c *gin.Context) {
  475. var req md.SetMobReq
  476. err := c.ShouldBindJSON(&req)
  477. if err != nil {
  478. err = validate.HandleValidateErr(err)
  479. err1 := err.(e.E)
  480. e.OutErr(c, err1.Code, err1.Error())
  481. return
  482. }
  483. masterId := svc.GetMasterId(c)
  484. engine := db.DBs[masterId]
  485. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  486. sysCfgDb.SysCfgUpdate("mob_app_key", req.MobAppKey)
  487. sysCfgDb.SysCfgUpdate("mob_app_secret", req.MobAppSecret)
  488. svc.ClearRedis(c, masterId, "mob_app_key")
  489. svc.ClearRedis(c, masterId, "mob_app_secret")
  490. svc.ClearAllRedis(c, masterId)
  491. e.OutSuc(c, "success", nil)
  492. return
  493. }
  494. // GetMob
  495. // @Summary mob获取
  496. // @Tags 设置中心-基础设置
  497. // @Description 基础设置-mob获取
  498. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  499. // @Accept json
  500. // @Produce json
  501. // @Success 200 {object} md.SetOssResp
  502. // @Failure 400 {object} md.Response "具体错误"
  503. // @Router /api/setCenter/basic/getMob [GET]
  504. func GetMob(c *gin.Context) {
  505. masterId := svc.GetMasterId(c)
  506. engine := db.DBs[masterId]
  507. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  508. res := sysCfgDb.SysCfgFindWithDb("mob_app_key", "mob_app_secret")
  509. e.OutSuc(c, md.SetMobResp{
  510. Data: md.SetMobReq{
  511. MobAppSecret: res["mob_app_secret"],
  512. MobAppKey: res["mob_app_key"],
  513. },
  514. }, nil)
  515. return
  516. }
  517. // SetLogo
  518. // @Summary logo设置
  519. // @Tags 设置中心-基础设置
  520. // @Description 基础设置-logo设置
  521. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  522. // @Accept json
  523. // @Produce json
  524. // @Param args body md.SetLogoReq true "请求参数"
  525. // @Success 200 {string} "success"
  526. // @Failure 400 {object} md.Response "具体错误"
  527. // @Router /api/setCenter/basic/setLogo [POST]
  528. func SetLogo(c *gin.Context) {
  529. var req md.SetLogoReq
  530. err := c.ShouldBindJSON(&req)
  531. if err != nil {
  532. err = validate.HandleValidateErr(err)
  533. err1 := err.(e.E)
  534. e.OutErr(c, err1.Code, err1.Error())
  535. return
  536. }
  537. masterId := svc.GetMasterId(c)
  538. engine := db.DBs[masterId]
  539. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  540. sysCfgDb.SysCfgUpdate("medium_logo", req.MediumLogo)
  541. sysCfgDb.SysCfgUpdate("agent_logo", req.AgentLogo)
  542. svc.ClearRedis(c, masterId, "medium_logo")
  543. svc.ClearRedis(c, masterId, "agent_logo")
  544. svc.ClearAllRedis(c, masterId)
  545. e.OutSuc(c, "success", nil)
  546. return
  547. }
  548. // GetLogo
  549. // @Summary logo获取
  550. // @Tags 设置中心-基础设置
  551. // @Description 基础设置-logo获取
  552. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  553. // @Accept json
  554. // @Produce json
  555. // @Success 200 {object} md.SetLogoResp
  556. // @Failure 400 {object} md.Response "具体错误"
  557. // @Router /api/setCenter/basic/getLogo [GET]
  558. func GetLogo(c *gin.Context) {
  559. masterId := svc.GetMasterId(c)
  560. engine := db.DBs[masterId]
  561. sysCfgDb := implement2.NewSysCfgDb(engine, masterId)
  562. res := sysCfgDb.SysCfgFindWithDb("medium_logo", "agent_logo")
  563. e.OutSuc(c, md.SetLogoResp{
  564. Data: md.SetLogoReq{
  565. MediumLogo: res["medium_logo"],
  566. AgentLogo: res["agent_logo"],
  567. },
  568. }, nil)
  569. return
  570. }
  571. // AppletGetBlackList
  572. // @Summary 获取屏蔽的广告主
  573. // @Tags 设置中心-小程序设置-屏蔽规则
  574. // @Description 小程序设置-屏蔽规则-获取屏蔽的广告主
  575. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  576. // @Accept json
  577. // @Produce json
  578. // @Param args body md.AppletGetBlackListReq true "请求参数"
  579. // @Success 200 {object} md2.AgencyGetBlackListResp
  580. // @Failure 400 {object} md.Response "具体错误"
  581. // @Router /api/setCenter/basic/applet/shieldRules/getBlackList [POST]
  582. func AppletGetBlackList(c *gin.Context) {
  583. var req md.AppletGetBlackListReq
  584. err := c.ShouldBindJSON(&req)
  585. if err != nil {
  586. err = validate.HandleValidateErr(err)
  587. err1 := err.(e.E)
  588. e.OutErr(c, err1.Code, err1.Error())
  589. return
  590. }
  591. masterId := svc.GetMasterId(c)
  592. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  593. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  594. if err != nil {
  595. e.OutErr(c, e.ERR, err.Error())
  596. return
  597. }
  598. if wxOpenThirdPartyAppList == nil {
  599. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  600. return
  601. }
  602. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  603. if err != nil {
  604. e.OutErr(c, e.ERR, err.Error())
  605. return
  606. }
  607. var resp md2.AgencyGetBlackListResp
  608. err, resp = wxApiService.GetBlackList(req.Appid)
  609. if err != nil {
  610. e.OutErr(c, e.ERR, err.Error())
  611. return
  612. }
  613. e.OutSuc(c, resp, nil)
  614. return
  615. }
  616. // AppletAddBlackList
  617. // @Summary 添加屏蔽的广告主
  618. // @Tags 设置中心-小程序设置-屏蔽规则
  619. // @Description 小程序设置-屏蔽规则-添加屏蔽的广告主
  620. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  621. // @Accept json
  622. // @Produce json
  623. // @Param args body md.AppletAddBlackListReq true "请求参数"
  624. // @Success 200 {string} "success"
  625. // @Failure 400 {object} md.Response "具体错误"
  626. // @Router /api/setCenter/basic/applet/shieldRules/addBlackList [POST]
  627. func AppletAddBlackList(c *gin.Context) {
  628. var req md.AppletAddBlackListReq
  629. err := c.ShouldBindJSON(&req)
  630. if err != nil {
  631. err = validate.HandleValidateErr(err)
  632. err1 := err.(e.E)
  633. e.OutErr(c, err1.Code, err1.Error())
  634. return
  635. }
  636. masterId := svc.GetMasterId(c)
  637. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  638. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  639. if err != nil {
  640. e.OutErr(c, e.ERR, err.Error())
  641. return
  642. }
  643. if wxOpenThirdPartyAppList == nil {
  644. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  645. return
  646. }
  647. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  648. if err != nil {
  649. e.OutErr(c, e.ERR, err.Error())
  650. return
  651. }
  652. listStr, _ := json.Marshal([]interface{}{
  653. map[string]interface{}{
  654. "type": req.Kind,
  655. "id": req.Id,
  656. },
  657. })
  658. err = wxApiService.SetBlackList(req.Appid, 1, string(listStr))
  659. if err != nil {
  660. e.OutErr(c, e.ERR, err.Error())
  661. return
  662. }
  663. e.OutSuc(c, "success", nil)
  664. return
  665. }
  666. // AppletDelBlackList
  667. // @Summary 删除屏蔽的广告主
  668. // @Tags 设置中心-小程序设置-屏蔽规则
  669. // @Description 小程序设置-屏蔽规则-删除屏蔽的广告主
  670. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  671. // @Accept json
  672. // @Produce json
  673. // @Param args body md.AppletDelBlackListReq true "请求参数"
  674. // @Success 200 {string} "success"
  675. // @Failure 400 {object} md.Response "具体错误"
  676. // @Router /api/setCenter/basic/applet/shieldRules/delBlackList [POST]
  677. func AppletDelBlackList(c *gin.Context) {
  678. var req md.AppletDelBlackListReq
  679. err := c.ShouldBindJSON(&req)
  680. if err != nil {
  681. err = validate.HandleValidateErr(err)
  682. err1 := err.(e.E)
  683. e.OutErr(c, err1.Code, err1.Error())
  684. return
  685. }
  686. masterId := svc.GetMasterId(c)
  687. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  688. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  689. if err != nil {
  690. e.OutErr(c, e.ERR, err.Error())
  691. return
  692. }
  693. if wxOpenThirdPartyAppList == nil {
  694. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  695. return
  696. }
  697. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  698. if err != nil {
  699. e.OutErr(c, e.ERR, err.Error())
  700. return
  701. }
  702. listStr, _ := json.Marshal([]interface{}{
  703. map[string]interface{}{
  704. "type": req.Kind,
  705. "id": req.Id,
  706. },
  707. })
  708. err = wxApiService.SetBlackList(req.Appid, 2, string(listStr))
  709. if err != nil {
  710. e.OutErr(c, e.ERR, err.Error())
  711. return
  712. }
  713. e.OutSuc(c, "success", nil)
  714. return
  715. }
  716. // AppletGetAmsCategoryBlackList
  717. // @Summary 获取行业屏蔽信息
  718. // @Tags 设置中心-小程序设置-屏蔽规则
  719. // @Description 小程序设置-屏蔽规则-获取行业屏蔽信息
  720. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  721. // @Accept json
  722. // @Produce json
  723. // @Param args body md.AppletGetAmsCategoryBlackListReq true "请求参数"
  724. // @Success 200 {object} md.AppletGetAmsCategoryBlackListResp
  725. // @Failure 400 {object} md.Response "具体错误"
  726. // @Router /api/setCenter/basic/applet/shieldRules/getAmsCategoryBlackList [POST]
  727. func AppletGetAmsCategoryBlackList(c *gin.Context) {
  728. var req md.AppletGetAmsCategoryBlackListReq
  729. err := c.ShouldBindJSON(&req)
  730. if err != nil {
  731. err = validate.HandleValidateErr(err)
  732. err1 := err.(e.E)
  733. e.OutErr(c, err1.Code, err1.Error())
  734. return
  735. }
  736. masterId := svc.GetMasterId(c)
  737. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  738. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  739. if err != nil {
  740. e.OutErr(c, e.ERR, err.Error())
  741. return
  742. }
  743. if wxOpenThirdPartyAppList == nil {
  744. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  745. return
  746. }
  747. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  748. if err != nil {
  749. e.OutErr(c, e.ERR, err.Error())
  750. return
  751. }
  752. var data md2.GetAmsCategoryBlackListResp
  753. err, data = wxApiService.GetAmsCategoryBlackList(req.Appid)
  754. if err != nil {
  755. e.OutErr(c, e.ERR, err.Error())
  756. return
  757. }
  758. var resp md.AppletGetAmsCategoryBlackListResp
  759. amsCategoryArr := strings.Split(data.AmsCategory, "|")
  760. for _, v := range amsCategoryArr {
  761. resp.CheckedAmsCategory = append(resp.CheckedAmsCategory, struct {
  762. Value string `json:"value" example:"行业标识符"`
  763. Name string `json:"name" example:"行业名称"`
  764. }{
  765. Value: v,
  766. Name: enum.AmsCategory.String(enum.AmsCategory(v)),
  767. })
  768. }
  769. resp.AllAmsCategory = []struct {
  770. Value string `json:"value" example:"行业标识符"`
  771. Name string `json:"name" example:"行业名称"`
  772. }{
  773. {
  774. Value: enum.AmsCategoryForChess,
  775. Name: enum.AmsCategory.String(enum.AmsCategoryForChess),
  776. },
  777. {
  778. Value: enum.AmsCategoryForAdultSupplies,
  779. Name: enum.AmsCategory.String(enum.AmsCategoryForAdultSupplies),
  780. },
  781. {
  782. Value: enum.AmsCategoryForMEDICALHEALTH,
  783. Name: enum.AmsCategory.String(enum.AmsCategoryForMEDICALHEALTH),
  784. },
  785. {
  786. Value: enum.AmsCategoryForINSURANCE,
  787. Name: enum.AmsCategory.String(enum.AmsCategoryForINSURANCE),
  788. },
  789. {
  790. Value: enum.AmsCategoryForSECURITES,
  791. Name: enum.AmsCategory.String(enum.AmsCategoryForSECURITES),
  792. },
  793. {
  794. Value: enum.AmsCategoryForLOAN,
  795. Name: enum.AmsCategory.String(enum.AmsCategoryForLOAN),
  796. },
  797. {
  798. Value: enum.AmsCategoryForLIVINGSERVICESBEAUTY,
  799. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESBEAUTY),
  800. },
  801. {
  802. Value: enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT,
  803. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESENTERTAINMENT),
  804. },
  805. {
  806. Value: enum.AmsCategoryForLIVINGSERVICESOTHERS,
  807. Name: enum.AmsCategory.String(enum.AmsCategoryForLIVINGSERVICESOTHERS),
  808. },
  809. {
  810. Value: enum.AmsCategoryForFOODINDUSTRY,
  811. Name: enum.AmsCategory.String(enum.AmsCategoryForFOODINDUSTRY),
  812. },
  813. {
  814. Value: enum.AmsCategoryForRETAILANDGENERALMERCHANDISE,
  815. Name: enum.AmsCategory.String(enum.AmsCategoryForRETAILANDGENERALMERCHANDISE),
  816. },
  817. {
  818. Value: enum.AmsCategoryForFOODANDDRINK,
  819. Name: enum.AmsCategory.String(enum.AmsCategoryForFOODANDDRINK),
  820. },
  821. {
  822. Value: enum.AmsCategoryForTECHNICALSERVICE,
  823. Name: enum.AmsCategory.String(enum.AmsCategoryForTECHNICALSERVICE),
  824. },
  825. }
  826. e.OutSuc(c, resp, nil)
  827. return
  828. }
  829. // AppletSetAmsCategoryBlackList
  830. // @Summary 设置行业屏蔽信息
  831. // @Tags 设置中心-小程序设置-屏蔽规则
  832. // @Description 小程序设置-屏蔽规则-设置行业屏蔽信息
  833. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  834. // @Accept json
  835. // @Produce json
  836. // @Param args body md.AppletSetAmsCategoryBlackListReq true "请求参数"
  837. // @Success 200 {string} "success"
  838. // @Failure 400 {object} md.Response "具体错误"
  839. // @Router /api/setCenter/basic/applet/shieldRules/setAmsCategoryBlackList [POST]
  840. func AppletSetAmsCategoryBlackList(c *gin.Context) {
  841. var req md.AppletSetAmsCategoryBlackListReq
  842. err := c.ShouldBindJSON(&req)
  843. if err != nil {
  844. err = validate.HandleValidateErr(err)
  845. err1 := err.(e.E)
  846. e.OutErr(c, err1.Code, err1.Error())
  847. return
  848. }
  849. masterId := svc.GetMasterId(c)
  850. wxOpenThirdPartyAppListDb := implement.NewWxOpenThirdPartyAppListDb(db.Db)
  851. wxOpenThirdPartyAppList, err := wxOpenThirdPartyAppListDb.GetWxOpenThirdPartyAppList(utils.StrToInt(masterId))
  852. if err != nil {
  853. e.OutErr(c, e.ERR, err.Error())
  854. return
  855. }
  856. if wxOpenThirdPartyAppList == nil {
  857. e.OutErr(c, e.ERR_NOT_FAN, "未查询到对应三方应用记录")
  858. return
  859. }
  860. wxApiService, err := wechat.NewWxApiService(masterId, wxOpenThirdPartyAppList.Appid, wxOpenThirdPartyAppList.AppSecret)
  861. if err != nil {
  862. e.OutErr(c, e.ERR, err.Error())
  863. return
  864. }
  865. amsCategory := strings.Join(req.CheckedAmsCategory, "|")
  866. err = wxApiService.SetAmsCategoryBlackList(req.Appid, amsCategory)
  867. if err != nil {
  868. e.OutErr(c, e.ERR, err.Error())
  869. return
  870. }
  871. e.OutSuc(c, "success", nil)
  872. return
  873. }