From db532b1f55c266b44877f053017cdd260a7ab5d8 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Fri, 19 May 2017 12:35:54 +1000 Subject: [PATCH] generate qr code 0 on edit_profile --- qrcode.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ qrcode_test.go | 8 ++++++++ 2 files changed, 52 insertions(+) create mode 100644 qrcode.go create mode 100644 qrcode_test.go diff --git a/qrcode.go b/qrcode.go new file mode 100644 index 0000000..5031e3e --- /dev/null +++ b/qrcode.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" +) + +type QRLimitScene struct { + Name string `json:"action_name"` + Info struct { + Scene struct { + ID int32 `json:"scene_id"` + IDstr string `json:"scene_str"` + } `json:"scene"` + } `json:"action_info"` +} + +//CreateProfileEditQR, give user a temp password to login +//for editing one's own profile +func CreateProfileEditQR() { + // http请求方式: POST + // URL: https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKENPOST数据格式:json + // POST数据例子:{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": 123}}} + // 或者也可以使用以下POST数据创建字符串形式的二维码参数: + // {"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}} + u := getURL4QRPerm() + s := QRLimitScene{} + s.Name = "QR_LIMIT_SCENE" + s.Info.Scene.IDstr = "edit_profile" + j, _ := json.Marshal(s) + log.Println(string(j)) + postJSON(j, u) + + //{"ticket":"gQEm8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyS19UblE5Z3VjU2gxMDAwME0wM04AAgRMYh1ZAwQAAAAA","url":"http:\/\/weixin.qq.com\/q\/02K_TnQ9gucSh10000M03N"} + //image: https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=gQEm8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyS19UblE5Z3VjU2gxMDAwME0wM04AAgRMYh1ZAwQAAAAA +} + +func getURL4QRPerm() (URL string) { + atk, _ := GetAccessToken() + u := fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", atk) + log.Println(u) + return u +} diff --git a/qrcode_test.go b/qrcode_test.go new file mode 100644 index 0000000..7e835a5 --- /dev/null +++ b/qrcode_test.go @@ -0,0 +1,8 @@ +package main + +import "testing" + +func TestCreatePermQR(t *testing.T) { + SetupConfig() + CreateProfileEditQR() +}