Răsfoiți Sursa

修改weixin

renzheng 9 ani în urmă
părinte
comite
75bb3db59c
2 a modificat fișierele cu 14 adăugiri și 12 ștergeri
  1. 12 10
      oauthproxy/src/main.go
  2. 2 2
      weixin/src/qfw/weixin/menu.go

+ 12 - 10
oauthproxy/src/main.go

@@ -4,9 +4,11 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
+	"log"
 	"net/http"
 	"qfw/util"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -59,26 +61,26 @@ func weixinOauth(w http.ResponseWriter, r *http.Request) {
 	msiteaction
 	**/
 
-	r.ParseForm()
-	action, code, _ := r.Form["action"][0], r.Form["code"][0], r.Form["state"][0]
-	/**
-	var urltpl string
-	if v, ok := proxy[action]; ok {
-		urltpl, _ = v.(string)
-	} else {
-		fmt.Fprintln(w, ERROR_TEMPLATE)
+	uri := r.RequestURI
+	if strings.Index(uri, "?") < 0 {
 		return
 	}
-	**/
+	start, end := strings.LastIndex(uri, "/"), strings.Index(uri, "?")
+	action := uri[start+1 : end]
+	log.Println("action", action)
+	//
+	r.ParseForm()
+	code, _ := r.Form["code"][0], r.Form["state"][0]
 
 	//取得openid
 	url := fmt.Sprintf(OPENAUTH_URLTPL, AppId, AppSecret, code)
+	log.Println("request url:", url)
 	resp, err := http.Get(url)
 	defer resp.Body.Close()
 	if err == nil {
 		//取得openid,unionid
 		bs, _ := ioutil.ReadAll(resp.Body)
-		//fmt.Println("data:", string(bs))
+		fmt.Println("data:", string(bs))
 		tmp := map[string]interface{}{}
 		err = json.Unmarshal(bs, &tmp)
 		if err != nil {

+ 2 - 2
weixin/src/qfw/weixin/menu.go

@@ -11,8 +11,8 @@ import (
 //创建微信自定义菜单
 func CreateMenu(rw http.ResponseWriter, r *http.Request) {
 
-	urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth?action=%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
-
+	urlstr := "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + wf.SysConfig.Appid + "&redirect_uri=http://" + wf.SysConfig.Domain + "/weixinoauth/action/%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
+	log.Println("menu", urlstr)
 	menu := &Menu{make([]MenuButton, 3)}
 
 	menu.Buttons[0].Name = "剑鱼"