ソースを参照

update

order_statistics
dengbiao 4ヶ月前
コミット
9b4d4952e9
8個のファイルの変更142行の追加269行の削除
  1. +2
    -1
      consume/init.go
  2. +10
    -0
      consume/md/consume_key.go
  3. +125
    -0
      consume/super_cloud_issuance_async_mlogin.go
  4. +4
    -1
      go.mod
  5. +0
    -109
      super_cloud_issuance/db/db_sys_mod_format_img.go
  6. +0
    -54
      super_cloud_issuance/lib/qiniu/req_img_upload.go
  7. +0
    -103
      super_cloud_issuance/svc/svc_file_img_upload.go
  8. +1
    -1
      super_cloud_issuance/tool/super_cloud_issuance/api.go

+ 2
- 1
consume/init.go ファイルの表示

@@ -96,10 +96,11 @@ func initConsumes() {
//jobs[consumeMd.ZhiosOneCirclesCoinConsumeFunName] = ZhiosOneCirclesCoinConsume //一个圈圈虚拟币变化

//////////////////////////////////////// autoRepaid /////////////////////////////////////////////////////
jobs[consumeMd.InstallmentPaymentAutoRepaidConsumeFunName] = InstallmentPaymentAutoRepaidConsume //分期付 - 自动扣款
//jobs[consumeMd.InstallmentPaymentAutoRepaidConsumeFunName] = InstallmentPaymentAutoRepaidConsume //分期付 - 自动扣款

////////////////////////////////////// SuperCloudIssuance /////////////////////////////////////////////////////
//jobs[consumeMd.SuperCloudIssuanceMsgCallBackFunName] = SuperCloudIssuanceMsgCallBackConsume
jobs[consumeMd.SuperCloudIssuanceAsyncMLoginFunName] = SuperCloudIssuanceAsyncMLoginConsume
}

func Run() {


+ 10
- 0
consume/md/consume_key.go ファイルの表示

@@ -20,6 +20,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "CloudIssuanceAsyncMLoginConsume",
},
{
ExchangeName: "",
Name: "super_cloud_issuance_async_mlogin",
Type: SimpleQueueType,
IsPersistent: false,
RoutKey: "",
BindKey: "",
ConsumeFunName: "SuperCloudIssuanceAsyncMLoginConsume",
},
{
ExchangeName: "zhios.cloud.issuance.msg.callback.exchange",
Name: "cloud_issuance_msg_call_back",
@@ -554,6 +563,7 @@ const (
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate"
CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume"
CloudIssuanceMsgCallBackFunName = "CloudIssuanceMsgCallBackConsume"
SuperCloudIssuanceAsyncMLoginFunName = "SuperCloudIssuanceAsyncMLoginConsume"
SuperCloudIssuanceMsgCallBackFunName = "SuperCloudIssuanceMsgCallBackConsume"
ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition"
ZhiosValidUserFunName = "ZhiosValidUser"


+ 125
- 0
consume/super_cloud_issuance_async_mlogin.go ファイルの表示

@@ -0,0 +1,125 @@
package consume

import (
"applet/app/cfg"
"applet/app/db"
"applet/app/utils"
"applet/app/utils/cache"
tool "applet/app/utils/cloud_issuance"
"applet/app/utils/logx"
md2 "applet/cloud_issuance/md"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"strconv"
"time"
)

func SuperCloudIssuanceAsyncMLoginConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
fmt.Println(">>>>>>>>>>>>>>>>SuperCloudIssuanceAsyncMLoginConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
//解析mq中queue的数据结构体
var msg *md2.CloudIssuanceAsyncMLogin
err = json.Unmarshal(res.Body, &msg)
if err != nil {
panic(err)
}
go func() {
err := handleSuperAsyncMLogin(msg.WId, msg.MasterId, msg.UserId, msg.RobotId)
if err != nil {
fmt.Println("<<<<<<<<<<<< handleSuperAsyncMLogin err>>>>>>>>", err.Error())
}
}()
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleSuperAsyncMLogin(wId, masterId, userId string, robotId int) error {
var timeTotal = 0
for {
err, resp := robotSuperAsyncMacLogin(md2.RobotAsyncMacLoginRequest{
WId: wId,
RobotId: robotId,
})
if err == nil {
fmt.Println("success <<<<<<<", resp)
if cfg.Prd {
engine := db.DBs[masterId]
cloudIssuanceUserRobotDb := implement.NewSuperCloudIssuanceUserRobotDb(engine, utils.StrToInt(userId), masterId)
robot, err := cloudIssuanceUserRobotDb.GetSuperCloudIssuanceUserRobot()
if err != nil {
return err
}
if robot == nil {
return errors.New("未查询到机器人记录")
}
robot.WcId = resp.WcId
robot.WcNickname = resp.NickName
robot.WcHeadUrl = resp.HeadUrl
robot.LoginStatus = 1
_, err = cloudIssuanceUserRobotDb.SaveSuperCloudIssuanceUserRobot(robot.Id, robot, "wc_id", "wc_nickname", "wc_head_url", "login_status")
if err != nil {
return err
}
} else {
//TODO::测试环境, 简化操作 通过redis 桥接
cache.SetEx(fmt.Sprintf("super_cloud_issuance_async_login_success:%s:%s", masterId, userId), utils.SerializeStr(resp), 60*5)
}
return nil
}

fmt.Println("err>>>>>>>>", err.Error())
if err != nil && err.Error() != "未登录" {
return err
}
//TODO::休眠5s
time.Sleep(time.Duration(5) * time.Second)
timeTotal += 5
if timeTotal >= 240 {
return errors.New("超时未登录")
}
}
}

func robotSuperAsyncMacLogin(args md2.RobotAsyncMacLoginRequest) (err error, result md2.RobotAsyncMacLoginResponse) { // 同步登录状态
url := tool.HttpBuild("itaoke.robot.async.mlogin", "127.0.0.1", map[string]string{
"robot_id": strconv.Itoa(args.RobotId),
"wId": args.WId,
})
data, err := tool.SendPost(url, args)
if err != nil {
return
}
resByte, err := json.Marshal(data.Data)
if err != nil {
return
}
err = json.Unmarshal(resByte, &result)
if err != nil {
return
}
return
}

+ 4
- 1
go.mod ファイルの表示

@@ -9,12 +9,14 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240703034234-2ab228956242
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240611024753-7cd929a03014
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/boombuler/barcode v1.0.1
github.com/cc14514/go-geoip2 v0.0.0-20190105051856-0a1854480a11
github.com/cc14514/go-geoip2-db v0.0.0-20190106063142-7b6408a9812a
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/forgoer/openssl v1.2.1
github.com/gin-contrib/sessions v1.0.0
github.com/gin-gonic/gin v1.9.1
@@ -29,6 +31,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.1.1
github.com/mingrammer/commonregex v1.0.1
github.com/qiniu/api.v7/v7 v7.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/shopspring/decimal v1.3.1
github.com/sony/sonyflake v1.0.0
@@ -45,7 +48,6 @@ require (
)

require (
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240701102131-0408d7ee8572 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
@@ -63,6 +65,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gookit/color v1.3.6 // indirect
github.com/gorilla/context v1.1.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/sessions v1.2.2 // indirect


+ 0
- 109
super_cloud_issuance/db/db_sys_mod_format_img.go ファイルの表示

@@ -1,77 +1,9 @@
package db

import (
"applet/app/cfg"
"applet/app/utils/logx"
"fmt"
"github.com/syyongx/php2go"
"regexp"
"strings"

"github.com/gin-gonic/gin"
)

func ReformatStr(str string, c *gin.Context) string {
protocol := SysCfgGet(c, "file_bucket_scheme")
domain := SysCfgGet(c, "file_bucket_host")

// PNG
replaceList := reformatPng(str)
l := removeDuplicateElement(replaceList)
for _, s := range l {
if strings.Contains(s, "http") {
continue
}
s = strings.ReplaceAll(s, `\`, "")
s = php2go.Rawurlencode(s)
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s)
if skipHTTPPng(new) {
continue
}
ss := s
s = strings.ReplaceAll(s, `"`, "")
str = strings.Replace(str, ss, `"`+new+`"`, -1)
}

// JPG
replaceList = reformatJPG(str)
l = removeDuplicateElement(replaceList)
for _, s := range l {
if strings.Contains(s, "http") {
continue
}
s = strings.ReplaceAll(s, `\`, "")
s = php2go.Rawurlencode(s)
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s)
if skipHTTPPng(new) {
continue
}
ss := s
s = strings.ReplaceAll(s, `"`, "")
str = strings.Replace(str, ss, `"`+new+`"`, -1)
}

// GIF
replaceList = reformatGIF(str)
l = removeDuplicateElement(replaceList)
for _, s := range l {
if strings.Contains(s, "http") {
continue
}
s = strings.ReplaceAll(s, `\`, "")
s = php2go.Rawurlencode(s)
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s)
if skipHTTPPng(new) {
continue
}
ss := s
s = strings.ReplaceAll(s, `"`, "")
str = strings.Replace(str, ss, `"`+new+`"`, -1)
}

return str
}

// 正则匹配
func reformatPng(data string) []string {
re, _ := regexp.Compile(`"([^\"]*.png")`)
@@ -113,44 +45,3 @@ func removeDuplicateElement(addrs []string) []string {
// fmt.Println(temp)
return result
}

// 单挑记录获取
func SysCfgGet(c *gin.Context, key string) string {
eg := DBs[c.GetString("mid")]
if !cfg.Prd {
myCfg, err := SysCfgGetOne(eg, key)
if err != nil || myCfg == nil {
_ = logx.Error(err)
return ""
}
return myCfg.Val
}
res := SysCfgFind(c, key)
//fmt.Println(res)
if _, ok := res[key]; !ok {
return ""
}
return res[key]
}

// 多条记录获取
func SysCfgFind(c *gin.Context, keys ...string) map[string]string {
masterId := c.GetString("mid")
eg := DBs[c.GetString("mid")]
res := map[string]string{}
//TODO::判断keys长度(大于5个直接查数据库)
if len(keys) > 5 {
cfgList, _ := SysCfgGetAll(eg)
if cfgList == nil {
return nil
}
for _, v := range *cfgList {
res[v.Key] = v.Val
}
} else {
for _, key := range keys {
res[key] = SysCfgGetWithDb(eg, masterId, key)
}
}
return res
}

+ 0
- 54
super_cloud_issuance/lib/qiniu/req_img_upload.go ファイルの表示

@@ -1,54 +0,0 @@
package qiniu

import (
"applet/app/md"
"applet/app/utils"
"time"

"github.com/qiniu/api.v7/v7/auth/qbox"
_ "github.com/qiniu/api.v7/v7/conf"
"github.com/qiniu/api.v7/v7/storage"
)

// 请求图片上传地址信息
func ReqImgUpload(f *md.FileCallback, callbackUrl string) interface{} {
if ext := utils.FileExt(f.FileName); ext == "png" || ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "bmp" || ext == "webp" {
f.Width = "$(imageInfo.width)"
f.Height = "$(imageInfo.height)"
}
f.Provider = "qiniu"
f.FileSize = "$(fsize)"
f.Hash = "$(etag)"
f.Bucket = "$(bucket)"
f.Mime = "$(mimeType)"
f.Time = utils.Int64ToStr(time.Now().Unix())
f.Sign = Sign(f.Time)
putPolicy := storage.PutPolicy{
Scope: BUCKET + ":" + f.FileName, // 使用覆盖方式时候必须请求里面有key,否则报错
Expires: Expires,
ForceSaveKey: true,
SaveKey: f.FileName,
MimeLimit: "image/*", // 只允许上传图片
CallbackURL: callbackUrl,
CallbackBody: utils.SerializeStr(f),
CallbackBodyType: "application/json",
}
return &struct {
Method string `json:"method"`
Key string `json:"key"`
Host string `json:"host"`
Token string `json:"token"`
}{Key: f.FileName, Method: "POST", Host: BUCKET_SCHEME + "://" + BUCKET_REGION, Token: putPolicy.UploadToken(qbox.NewMac(AK, SK))}
}

/*
form表单上传
地址 : http://upload-z2.qiniup.com
header
- Content-Type : multipart/form-data

body :
- key : 文件名
- token : 生成token
- file : 待上传文件
*/

+ 0
- 103
super_cloud_issuance/svc/svc_file_img_upload.go ファイルの表示

@@ -1,103 +0,0 @@
package svc

import (
"applet/app/e"
"applet/app/utils"
"applet/super_cloud_issuance/lib/qiniu"
"applet/super_cloud_issuance/md"
"applet/super_cloud_issuance/utils/logx"
"fmt"
"strings"

"github.com/gin-gonic/gin"
)

// 请求文件上传
func ImgReqUpload(c *gin.Context, uid, dirName, fname, callbackUrl string, fsize int64) (interface{}, error) {
ext := utils.FileExt(fname)
if err := initStg(c, fsize, ext); err != nil {
return nil, err
}
// logx.Warn(uid)
newName := dirName + "_" + fmt.Sprintf("%010s", uid)

// if dirName == md.FILE_DIR_FEEDBACK || dirName == md.FILE_DIR_STYLE {
// newName += "_" + utils.FormatNanoUnix() + utils.RandString(4, "0123456789")
// }
// 默认都加时间戳
newName += "_" + utils.FormatNanoUnix() + utils.RandString(4, "0123456789")
newName += ".png" // 因为可能存在多种图像格式,这里统一后缀为png

f := &md.FileCallback{
Uid: uid,
DirId: md.FileUserDir[dirName],
FileName: newName,
}
// logx.Warn(f.Uid)
return qiniu.ReqImgUpload(f, callbackUrl), nil
}

func initStg(c *gin.Context, fsize int64, ext string) error {
// 获取上传配置
stgInfo := SysCfgFind(
c,
md.KEY_CFG_FILE_BUCKET,
md.KEY_CFG_FILE_HOST,
md.KEY_CFG_FILE_AK,
md.KEY_CFG_FILE_SK,
md.KEY_CFG_FILE_PVD,
md.KEY_CFG_FILE_REGION,
md.KEY_CFG_FILE_MAX_SIZE,
md.KEY_CFG_FILE_EXT,
md.KEY_CFG_FILE_SCHEME,
md.KEY_CFG_FILE_AVATAR_THUMBNAIL,
)
//?imageView2/1/w/120/h/120/format/webp/interlace/1
if stgInfo == nil {
return e.NewErrCode(e.ERR_CFG)
}
// todo 目前仅支持七牛
if v, ok := stgInfo[md.KEY_CFG_FILE_PVD]; !ok || v != "qiniu" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_REGION]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_AK]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_SK]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_BUCKET]; !ok || v == "" {
return e.NewErrCode(e.ERR_CFG)
}
if v, ok := stgInfo[md.KEY_CFG_FILE_SCHEME]; !ok || v == "" {
stgInfo[md.KEY_CFG_FILE_SCHEME] = "http"
SysCfgSet(c, md.KEY_CFG_FILE_SCHEME, stgInfo[md.KEY_CFG_FILE_SCHEME], "文件域名HTTP协议")
}
qiniu.Init(stgInfo[md.KEY_CFG_FILE_AK], stgInfo[md.KEY_CFG_FILE_SK], stgInfo[md.KEY_CFG_FILE_BUCKET], stgInfo[md.KEY_CFG_FILE_REGION], stgInfo[md.KEY_CFG_FILE_SCHEME])
if v, ok := stgInfo[md.KEY_CFG_FILE_HOST]; !ok || v == "" {
var err error
stgInfo[md.KEY_CFG_FILE_HOST], err = qiniu.BucketGetDomain(stgInfo[md.KEY_CFG_FILE_BUCKET])
if err != nil {
logx.Error(err)
return e.NewErrCode(e.ERR_CFG)
}
SysCfgSet(c, md.KEY_CFG_FILE_HOST, stgInfo[md.KEY_CFG_FILE_HOST], "文件域名地址")
}
// 头像缩略图参数
if v, ok := stgInfo[md.KEY_CFG_FILE_AVATAR_THUMBNAIL]; !ok || v == "" {
SysCfgSet(c, md.KEY_CFG_FILE_AVATAR_THUMBNAIL, "?imageView2/1/w/200/h/200/format/png", "文件用户头像缩略图参数")
}

// 检查文件大小限制
if v, ok := stgInfo[md.KEY_CFG_FILE_MAX_SIZE]; ok && v != "" && utils.StrToInt64(v) < fsize {
return e.NewErrCode(e.ERR_FILE_MAX_SIZE)
}
// 检查文件后缀
if v, ok := stgInfo[md.KEY_CFG_FILE_EXT]; ok && v != "" && !strings.Contains(v, ext) {
return e.NewErrCode(e.ERR_FILE_EXT)
}
return nil
}

+ 1
- 1
super_cloud_issuance/tool/super_cloud_issuance/api.go ファイルの表示

@@ -1,8 +1,8 @@
package super_cloud_issuance

import (
"applet/app/md"
"applet/app/utils"
"applet/super_cloud_issuance/md"
"encoding/json"
"errors"
"fmt"


読み込み中…
キャンセル
保存