Browse Source

wip:新增获取域名及微信自动登录

wangkaiyue 3 năm trước cách đây
mục cha
commit
f22c7483d1

+ 8 - 5
src/jfw/front/frontRouter.go

@@ -3,8 +3,10 @@ package front
 import (
 	"fmt"
 	"jfw/config"
+	"jfw/jyutil"
 	"jfw/public"
 	"jfw/wx"
+	"net/url"
 	"qfw/util/jy"
 	"regexp"
 	"strings"
@@ -63,13 +65,14 @@ func init() {
 func (this *CommonRouter) WxCommonPage(folder, loginSign, htmlPage string) error {
 	if loginSign != "free" {
 		openid, _ := this.GetSession("s_m_openid").(string)
-		if openid != "" {
-			ok, _, _ := FindUserAndCreateSess(openid, this.Session(), "wx", false)
-			if !ok {
-				openid = ""
+		if openid == "" || (openid != "" && !CheckUserIsSubscribe(openid)) {
+			stateKey := this.GetString("state")
+			if stateKey == "" { //公众号回调
+				return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), stateKey), 302)
 			}
+			openid = jyutil.Getopenid(this.GetString("code"))
 		}
-		if openid == "" {
+		if !CheckUserIsSubscribe(openid) {
 			return this.Redirect("/swordfish/about")
 		}
 	}

+ 1 - 0
src/jfw/modules/subscribepay/src/config.json

@@ -67,6 +67,7 @@
   	"appPushServiceRpc": "127.0.0.1:5566",
   	"webdomain": "http://web-zxl.jydev.jianyu360.com",
   	"appdomain": "http://web-zxl.jydev.jianyu360.com",
+    "wxdomain": "http://web-zxl.jydev.jianyu360.com",
   	"mail": [
 	    {
 	      "addr": "smtp.exmail.qq.com",

+ 1 - 0
src/jfw/modules/subscribepay/src/config/config.go

@@ -51,6 +51,7 @@ type config struct {
 	AppPushServiceRpc string
 	WebDomain         string
 	AppDomain         string
+	WxDomain          string
 	Mail              []struct {
 		Addr string
 		Port int

+ 11 - 1
src/jfw/modules/subscribepay/src/service/commonAction.go

@@ -30,6 +30,7 @@ import (
 type CommonAction struct {
 	*xweb.Action
 	getwxSdkSign         xweb.Mapper `xweb:"/wx/getwxSdkSign"`             //微信js参数
+	getDomain            xweb.Mapper `xweb:"/getDomain"`                   //微信js参数
 	getCommonOrderPrice  xweb.Mapper `xweb:"/common/getOrderPrice"`        //获取订单价格
 	getCommonPayParam    xweb.Mapper `xweb:"/common/getPayParam"`          //公共获取支付方法
 	saveTransferAccounts xweb.Mapper `xweb:"/common/saveTransferAccounts"` //公共对公转账接口
@@ -42,6 +43,14 @@ type CommonAction struct {
 
 var pdfNameReg = regexp.MustCompilePOSIX(`[^//]*\.pdf`)
 
+func (this *CommonAction) GetDomain() {
+	this.ServeJson(NewResult(map[string]interface{}{
+		"web": config.Config.WebDomain,
+		"app": config.Config.AppDomain,
+		"wx":  config.Config.WxDomain,
+	}, nil))
+}
+
 func (this *CommonAction) SendMailNote(mailType string) {
 	userId, _ := this.GetSession("userId").(string)
 	rData, errMsg := func() (interface{}, error) {
@@ -252,7 +261,8 @@ func (d *CommonAction) GetwxSdkSign() {
 		sign = SignJSSDK(url)
 	}
 	d.ServeJson(map[string]interface{}{
-		"wxsdk": sign,
+		"wxsdk":    sign,
+		"wxDomain": config.Config.WxDomain,
 	})
 }