sellerOrder.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package util
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "jy/src/jfw/modules/subscribepay/src/config"
  7. "net/http"
  8. "net/url"
  9. "time"
  10. "app.yhyue.com/moapp/jypkg/identity"
  11. qutil "app.yhyue.com/moapp/jybase/common"
  12. . "app.yhyue.com/moapp/jybase/date"
  13. "app.yhyue.com/moapp/jybase/encrypt"
  14. "app.yhyue.com/moapp/jybase/go-xweb/log"
  15. )
  16. // SellerTokenDecrypt 销售代用户下单公共方法
  17. // param : token
  18. // return :
  19. //
  20. // uId 用户id
  21. // sName 销售名字
  22. // sid 销售id
  23. // desc map[string]interface{}
  24. // 超级订阅:tn:周期 1:天、2:月
  25. // tt:数量
  26. // err 异常
  27. func SellerTokenDecrypt(token string) (uId, sName string, sid string, desc map[string]interface{}, err error) {
  28. if token == "" {
  29. err = fmt.Errorf("缺少token")
  30. return
  31. }
  32. param, err := url.ParseQuery(encrypt.SE.Decode4Hex(token))
  33. if err != nil {
  34. err = fmt.Errorf("token格式异常")
  35. return
  36. }
  37. //if qutil.Int64All(param.Get("t")) < time.Now().Unix()-int64(60*5) {
  38. // err = fmt.Errorf("链接已失效")
  39. // return
  40. //}
  41. //取参数
  42. err = json.Unmarshal([]byte(param.Get("desc")), &desc)
  43. if err != nil {
  44. err = fmt.Errorf("token参数格式异常")
  45. return
  46. }
  47. uId = param.Get("uid")
  48. sName = param.Get("sName")
  49. sid = qutil.ObjToString(param.Get("sid"))
  50. if uId == "" || sName == "" || sid == "" || len(desc) == 0 {
  51. err = fmt.Errorf("缺少参数")
  52. return
  53. }
  54. return
  55. }
  56. // GetSellerToken 销售创建订单加密参数
  57. //
  58. // param
  59. // uId 用户id
  60. // sName 销售名字
  61. // sid 销售id
  62. // desc map[string]interface{}
  63. // 超级订阅:tn:周期 1:天、2:月
  64. // tt:数量
  65. // return
  66. // token 加密信息
  67. func GetSellerToken(uId, sName string, sid string, desc map[string]interface{}) (token string) {
  68. bytes, _ := json.Marshal(desc)
  69. return encrypt.SE.Encode2Hex(fmt.Sprintf("uid=%s&sName=%s&sid=%s&desc=%s&t=%d", uId, sName, sid, string(bytes), time.Now().Unix()))
  70. }
  71. type MessageRet struct {
  72. Status string `json:"status"`
  73. Info string `json:"info"`
  74. Data struct {
  75. Status int `json:"status"`
  76. } `json:"data"`
  77. }
  78. /*
  79. SendStationMessages 站内信发送
  80. _action /message/sendMessageApi
  81. userIds 用户userId用英文逗号拼接
  82. msgType 消息类型 1-活动优惠 2-服务通知 3-订阅消息 4-项目动态 5-企业动态 6-分析报告 7-系统通知
  83. title 通知消息 消息标题
  84. content 消息内容
  85. link pc消息链接
  86. sendMode 发送模式 1- 定时 2-实时
  87. sendTime 2022-03-31 发送时间
  88. androidUrl 安卓消息链接
  89. iosUrl IOS消息链接
  90. weChatUrl 微信消息链接
  91. _token 是
  92. */
  93. func SendStationMessages(href, userId, action, msgType, title, content, link, androidUrl, iosUrl, weChatUrl, OrderCode string, VipType, OrderMoney int) {
  94. //websiteInformation := -1
  95. var (
  96. ret MessageRet
  97. cont []byte
  98. )
  99. user, _ := MQFW.FindById("user", userId, `{"base_user_id":1}`)
  100. if user != nil && qutil.IntAll((*user)["base_user_id"]) > 0 {
  101. var token string
  102. identityList := config.Middleground.UserCenter.IdentityList(qutil.Int64All((*user)["base_user_id"]))
  103. for _, v := range identityList {
  104. if v.PositionType == 0 {
  105. token = encode(&identity.IdentityInfo{
  106. Name: v.Name,
  107. PersonId: v.PersonId,
  108. UserName: v.UserName,
  109. AccountId: v.AccountId,
  110. EntAccountId: v.EntAccountId,
  111. PositionId: v.PositionId,
  112. PositionType: v.PositionType,
  113. EntId: v.EntId,
  114. EntUserId: v.EntUserId,
  115. EntUserName: v.EntUserName,
  116. })
  117. break
  118. }
  119. }
  120. if token != "" {
  121. androidUrl = fmt.Sprintf("%s&identity=%s", androidUrl, token)
  122. }
  123. }
  124. name := "超级订阅"
  125. if VipType == 1 {
  126. name = "超级订阅(续费)"
  127. }
  128. pushHref := fmt.Sprintf("%s?_action=%s&userIds=%s&msgType=%s&title=%s&content=%s&link=%s&sendMode=2&sendTime=%s&androidUrl=%s&iosUrl=%s&weChatUrl=%s&_token=12311&reqSource=1&callPlatform=dyhxd&name=%s&orderid=%s&ordermoney=%.2f&details=您的订单%s处于未支付状态,为了使您获取更多...",
  129. href, action, userId, msgType, title, content, link, NowFormat(Date_Short_Layout), androidUrl, iosUrl, weChatUrl, name, OrderCode, float64(OrderMoney)/100, OrderCode)
  130. log.Info("href:", pushHref)
  131. log.Println(pushHref)
  132. resp, err := http.Get(pushHref)
  133. if err != nil {
  134. log.Error(err)
  135. return
  136. }
  137. defer resp.Body.Close()
  138. cont, err = ioutil.ReadAll(resp.Body)
  139. log.Info(string(cont))
  140. log.Println(string(cont), err)
  141. if err != nil {
  142. log.Error(err)
  143. return
  144. }
  145. err = json.Unmarshal(cont, &ret)
  146. if err != nil {
  147. log.Error(err)
  148. return
  149. }
  150. if ret.Data.Status != 1 {
  151. log.Error(ret)
  152. }
  153. //env:
  154. // filterData := Mysql.FindOne("dataexport_order", map[string]interface{}{"id": orderId}, "id,filter", "")
  155. // if filterData != nil && len(*filterData) > 0 {
  156. // filterMap := make(map[string]interface{})
  157. // filter := qutil.InterfaceToStr((*filterData)["filter"])
  158. // if filter != "" {
  159. // if err = json.Unmarshal([]byte(qutil.InterfaceToStr((*filterData)["filter"])), &filterMap); err != nil {
  160. // log.Error(err.Error(), "更新订单异常Unmarshal")
  161. // return
  162. // }
  163. // }
  164. // filterMap["website_information"] = websiteInformation
  165. // bb, err := json.Marshal(filterMap)
  166. // if err != nil {
  167. // log.Error(err.Error(), "更新订单异常-Marshall")
  168. // return
  169. // }
  170. // Mysql.Update("dataexport_order", map[string]interface{}{"id": orderId}, map[string]interface{}{
  171. // "filter": string(bb),
  172. // })
  173. // }
  174. }
  175. // 加密
  176. func encode(i *identity.IdentityInfo) string {
  177. b, _ := json.Marshal(i)
  178. return encrypt.SE.Encode2Hex(string(b))
  179. }