123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package util
- import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "jy/src/jfw/modules/subscribepay/src/config"
- "net/http"
- "net/url"
- "time"
- "app.yhyue.com/moapp/jypkg/identity"
- qutil "app.yhyue.com/moapp/jybase/common"
- . "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jybase/go-xweb/log"
- )
- // SellerTokenDecrypt 销售代用户下单公共方法
- // param : token
- // return :
- //
- // uId 用户id
- // sName 销售名字
- // sid 销售id
- // desc map[string]interface{}
- // 超级订阅:tn:周期 1:天、2:月
- // tt:数量
- // err 异常
- func SellerTokenDecrypt(token string) (uId, sName string, sid string, desc map[string]interface{}, err error) {
- if token == "" {
- err = fmt.Errorf("缺少token")
- return
- }
- param, err := url.ParseQuery(encrypt.SE.Decode4Hex(token))
- if err != nil {
- err = fmt.Errorf("token格式异常")
- return
- }
- //if qutil.Int64All(param.Get("t")) < time.Now().Unix()-int64(60*5) {
- // err = fmt.Errorf("链接已失效")
- // return
- //}
- //取参数
- err = json.Unmarshal([]byte(param.Get("desc")), &desc)
- if err != nil {
- err = fmt.Errorf("token参数格式异常")
- return
- }
- uId = param.Get("uid")
- sName = param.Get("sName")
- sid = qutil.ObjToString(param.Get("sid"))
- if uId == "" || sName == "" || sid == "" || len(desc) == 0 {
- err = fmt.Errorf("缺少参数")
- return
- }
- return
- }
- // GetSellerToken 销售创建订单加密参数
- //
- // param
- // uId 用户id
- // sName 销售名字
- // sid 销售id
- // desc map[string]interface{}
- // 超级订阅:tn:周期 1:天、2:月
- // tt:数量
- // return
- // token 加密信息
- func GetSellerToken(uId, sName string, sid string, desc map[string]interface{}) (token string) {
- bytes, _ := json.Marshal(desc)
- return encrypt.SE.Encode2Hex(fmt.Sprintf("uid=%s&sName=%s&sid=%s&desc=%s&t=%d", uId, sName, sid, string(bytes), time.Now().Unix()))
- }
- type MessageRet struct {
- Status string `json:"status"`
- Info string `json:"info"`
- Data struct {
- Status int `json:"status"`
- } `json:"data"`
- }
- /*
- SendStationMessages 站内信发送
- _action /message/sendMessageApi
- userIds 用户userId用英文逗号拼接
- msgType 消息类型 1-活动优惠 2-服务通知 3-订阅消息 4-项目动态 5-企业动态 6-分析报告 7-系统通知
- title 通知消息 消息标题
- content 消息内容
- link pc消息链接
- sendMode 发送模式 1- 定时 2-实时
- sendTime 2022-03-31 发送时间
- androidUrl 安卓消息链接
- iosUrl IOS消息链接
- weChatUrl 微信消息链接
- _token 是
- */
- func SendStationMessages(href, userId, action, msgType, title, content, link, androidUrl, iosUrl, weChatUrl, OrderCode string, VipType, OrderMoney int) {
- //websiteInformation := -1
- var (
- ret MessageRet
- cont []byte
- )
- user, _ := MQFW.FindById("user", userId, `{"base_user_id":1}`)
- if user != nil && qutil.IntAll((*user)["base_user_id"]) > 0 {
- var token string
- identityList := config.Middleground.UserCenter.IdentityList(qutil.Int64All((*user)["base_user_id"]))
- for _, v := range identityList {
- if v.PositionType == 0 {
- token = encode(&identity.IdentityInfo{
- Name: v.Name,
- PersonId: v.PersonId,
- UserName: v.UserName,
- AccountId: v.AccountId,
- EntAccountId: v.EntAccountId,
- PositionId: v.PositionId,
- PositionType: v.PositionType,
- EntId: v.EntId,
- EntUserId: v.EntUserId,
- EntUserName: v.EntUserName,
- })
- break
- }
- }
- if token != "" {
- androidUrl = fmt.Sprintf("%s&identity=%s", androidUrl, token)
- }
- }
- name := "超级订阅"
- if VipType == 1 {
- name = "超级订阅(续费)"
- }
- 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处于未支付状态,为了使您获取更多...",
- href, action, userId, msgType, title, content, link, NowFormat(Date_Short_Layout), androidUrl, iosUrl, weChatUrl, name, OrderCode, float64(OrderMoney)/100, OrderCode)
- log.Info("href:", pushHref)
- log.Println(pushHref)
- resp, err := http.Get(pushHref)
- if err != nil {
- log.Error(err)
- return
- }
- defer resp.Body.Close()
- cont, err = ioutil.ReadAll(resp.Body)
- log.Info(string(cont))
- log.Println(string(cont), err)
- if err != nil {
- log.Error(err)
- return
- }
- err = json.Unmarshal(cont, &ret)
- if err != nil {
- log.Error(err)
- return
- }
- if ret.Data.Status != 1 {
- log.Error(ret)
- }
- //env:
- // filterData := Mysql.FindOne("dataexport_order", map[string]interface{}{"id": orderId}, "id,filter", "")
- // if filterData != nil && len(*filterData) > 0 {
- // filterMap := make(map[string]interface{})
- // filter := qutil.InterfaceToStr((*filterData)["filter"])
- // if filter != "" {
- // if err = json.Unmarshal([]byte(qutil.InterfaceToStr((*filterData)["filter"])), &filterMap); err != nil {
- // log.Error(err.Error(), "更新订单异常Unmarshal")
- // return
- // }
- // }
- // filterMap["website_information"] = websiteInformation
- // bb, err := json.Marshal(filterMap)
- // if err != nil {
- // log.Error(err.Error(), "更新订单异常-Marshall")
- // return
- // }
- // Mysql.Update("dataexport_order", map[string]interface{}{"id": orderId}, map[string]interface{}{
- // "filter": string(bb),
- // })
- // }
- }
- // 加密
- func encode(i *identity.IdentityInfo) string {
- b, _ := json.Marshal(i)
- return encrypt.SE.Encode2Hex(string(b))
- }
|