瀏覽代碼

Merge branch 'crm_15.7' into debug

# Conflicts:
#	services/wx_app/wx_app.go
zwxi 10 月之前
父節點
當前提交
5534c0d3ce
共有 5 個文件被更改,包括 55 次插入41 次删除
  1. 6 6
      config/config.go
  2. 26 20
      controller/public.go
  3. 1 1
      core/run_server.go
  4. 9 14
      init_serve/mongo.go
  5. 13 0
      services/wx_app/wx_app.go

+ 6 - 6
config/config.go

@@ -92,10 +92,10 @@ type EsClient struct {
 // Mongo
 // @Description: mongo配置
 type Mongo struct {
-	Host       string `mapstructure:"host" json:"host" yaml:"host" description:"mongo地址"`
-	Port       int    `mapstructure:"port" json:"port" yaml:"port" description:"mongo端口"`
-	AuthSource string `mapstructure:"auth-source" json:"auth-source" yaml:"auth-source" description:"认证数据库"`
-	Database   string `mapstructure:"database" json:"database" yaml:"database" description:"默认数据库"`
-	Username   string `mapstructure:"username" json:"username" yaml:"username" description:"用户名"`
-	Password   string `mapstructure:"password" json:"password" yaml:"password" description:"密码"`
+	Url           string `mapstructure:"url" json:"url" yaml:"url" description:"mongo地址url"`
+	AuthMechanism string `mapstructure:"auth_mechanism" json:"auth_mechanism" yaml:"auth_mechanism" description:"鉴权方式"`
+	AuthSource    string `mapstructure:"auth-source" json:"auth-source" yaml:"auth-source" description:"认证数据库"`
+	Database      string `mapstructure:"database" json:"database" yaml:"database" description:"默认数据库"`
+	Username      string `mapstructure:"username" json:"username" yaml:"username" description:"用户名"`
+	Password      string `mapstructure:"password" json:"password" yaml:"password" description:"密码"`
 }

+ 26 - 20
controller/public.go

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
-	"github.com/skip2/go-qrcode"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/logic"
@@ -23,6 +22,7 @@ import (
 	"hongze/hongze_yb/services"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
 	"io/ioutil"
 	"net/url"
@@ -544,35 +544,41 @@ func BannerGetQRCode(c *gin.Context) {
 	}
 	companyName := companyInfo.CompanyName
 
-	userInfo := user.GetInfoByClaims(c)
-	userDetail, err, errMsg := userLogic.GetUserInfo(userInfo)
-	if err != nil {
-		if errMsg != "" {
-			errMsg = "获取失败"
-		}
-		response.Fail(errMsg, c)
-		return
-	}
-	randStr := utils.GetRandStringNoSpecialChar(28)
-	filePath := "./static/" + randStr + ".png"
-	fileName := randStr + ".png"
-
 	companyNameCode := url.QueryEscape(companyName) // 进行URL编码
 	remarkCode := url.QueryEscape(remark) // 进行URL编码
 	url := "pages-report/signUpPage/signUpPage?RealName=%s&CompanyName=%s&Mobile=%s&BannerId=%d&Title=%s"
-	url = fmt.Sprintf(url, wxUserInfo.RealName, companyNameCode, userDetail.Mobile, bannerId, remarkCode)
+	url = fmt.Sprintf(url, wxUserInfo.RealName, companyNameCode, wxUserInfo.Mobile, bannerId, remarkCode)
 
-	err = qrcode.WriteFile(url, qrcode.Medium, 256, filePath)
+	picByte, err := wx_app.GetSunCodeV2(url)
 	if err != nil {
-		response.FailData("生成二维码失败", "生成二维码失败,Err:"+err.Error(), c)
+		return
+	}
+	// 生成图片
+	localPath := "./static/img"
+	fileName := utils.GetRandStringNoSpecialChar(28) + ".png"
+	fpath := fmt.Sprint(localPath, "/", fileName)
+	f, err := os.Create(fpath)
+	if err != nil {
+		return
+	}
+	if _, err = f.Write(picByte); err != nil {
+		return
 	}
-
 	defer func() {
-		os.Remove(filePath)
+		f.Close()
+		os.Remove(fpath)
 	}()
+	//err = qrcode.WriteFile(url, qrcode.Medium, 256, filePath)
+	//if err != nil {
+	//	response.FailData("生成二维码失败", "生成二维码失败,Err:"+err.Error(), c)
+	//}
+	//
+	//defer func() {
+	//	os.Remove(filePath)
+	//}()
 
 	//上传到阿里云
-	resourceUrl, err := services.UploadAliyun(fileName, filePath)
+	resourceUrl, err := services.UploadAliyun(fileName, fpath)
 	if err != nil {
 		response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
 		return

+ 1 - 1
core/run_server.go

@@ -17,7 +17,7 @@ func RunServe() {
 		init_serve.Redis()
 	}
 
-	if global.CONFIG.Mongo.Host != `` {
+	if global.CONFIG.Mongo.Url != `` {
 		//初始化redis
 		init_serve.InitMongo()
 	}

+ 9 - 14
init_serve/mongo.go

@@ -2,7 +2,6 @@ package init_serve
 
 import (
 	"context"
-	"fmt"
 	"github.com/qiniu/qmgo"
 	"github.com/qiniu/qmgo/options"
 	"go.mongodb.org/mongo-driver/bson"
@@ -76,20 +75,16 @@ func MgoNewClient() *qmgo.Client {
 
 	//mongodb+srv://myDatabaseUser:D1fficultP%40ssw0rd@mongodb0.example.com/?authSource=admin&replicaSet=myRepl
 
-	var mongoUrl string
-	if mgoConfig.Password != "" {
-		mongoUrl = fmt.Sprintf("mongodb://%s:%s@%s:%d", mgoConfig.Username, mgoConfig.Password, mgoConfig.Host, mgoConfig.Port)
-
-		if mgoConfig.AuthSource != `` {
-			mongoUrl += mongoUrl + "?&authSource=" + mgoConfig.AuthSource
-		}
-	} else {
-		mongoUrl = fmt.Sprintf("mongodb://%s:%d", mgoConfig.Host, mgoConfig.Port)
-	}
-
 	// 创建一个数据库链接
 	client, err := qmgo.NewClient(ctx, &qmgo.Config{
-		Uri:              mongoUrl,
+		Uri: mgoConfig.Url,
+		Auth: &qmgo.Credential{
+			AuthMechanism: mgoConfig.AuthMechanism,
+			AuthSource:    mgoConfig.AuthSource,
+			Username:      mgoConfig.Username,
+			Password:      mgoConfig.Password,
+			//PasswordSet:   false,
+		},
 		Database:         mgoConfig.Database,
 		ConnectTimeoutMS: &ConnectTimeoutMS,
 		SocketTimeoutMS:  &SocketTimeoutMS,
@@ -120,7 +115,7 @@ func MgoGetColl(collName string) (cli *qmgo.QmgoClient, err error) {
 }
 
 func InitMongo() {
-	if global.CONFIG.Mongo.Host != `` {
+	if global.CONFIG.Mongo.Url != `` {
 		mgoCli := MgoNewClient()
 		global.MgoDataCli = mgoCli
 	}

+ 13 - 0
services/wx_app/wx_app.go

@@ -182,3 +182,16 @@ func getWxAppConfByRequest(copyYb string) *WxAppConf {
 	}
 	return appConf
 }
+
+// GetSunCode 获取太阳码
+func GetSunCodeV2(page string) (resp []byte, err error) {
+	codePars := qrcode.QRCoder{
+		Path:       page,
+		EnvVersion: EnvVersion,
+		Width:      256,
+	}
+	wechatClient := GetWxApp()
+	qr := wechatClient.GetQRCode()
+	return qr.GetWXACode(codePars)
+}
+