parent
0661b4bd33
commit
0ebf74ce62
@ -1,26 +0,0 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GetTicketResult 返回参数
|
||||
type GetTicketResult struct {
|
||||
Errcode int `json:"errcode"` // 错误码
|
||||
Errmsg string `json:"errmsg"` // 错误信息
|
||||
Ticket string `json:"ticket"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
}
|
||||
|
||||
func (app *App) GetTicket(accessToken, Type string) (result GetTicketResult, err error) {
|
||||
// request
|
||||
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=%s", accessToken, Type), map[string]interface{}{}, "GET")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(body, &result); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (app *App) MessageTemplateSend(notMustParams ...Params) (body []byte, err error) {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s", app.AccessToken), params, "POST")
|
||||
return
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// UserInfo 请求参数
|
||||
type UserInfo struct {
|
||||
SessionKey string `json:"session_key"`
|
||||
EncryptedData string `json:"encrypted_data"`
|
||||
Iv string `json:"iv"`
|
||||
}
|
||||
|
||||
// UserInfoResult 返回参数
|
||||
type UserInfoResult struct {
|
||||
OpenID string `json:"openId"`
|
||||
NickName string `json:"nickName"`
|
||||
Gender int `json:"gender"`
|
||||
City string `json:"city"`
|
||||
Province string `json:"province"`
|
||||
Country string `json:"country"`
|
||||
AvatarUrl string `json:"avatarUrl"`
|
||||
UnionId string `json:"unionId"`
|
||||
Watermark struct {
|
||||
AppID string `json:"appid"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
} `json:"watermark"`
|
||||
}
|
||||
|
||||
// UserInfo 解密用户信息
|
||||
func (app *App) UserInfo(param UserInfo) (result UserInfoResult, err error) {
|
||||
aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
cipherText, err := base64.StdEncoding.DecodeString(param.EncryptedData)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
ivBytes, err := base64.StdEncoding.DecodeString(param.Iv)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
block, err := aes.NewCipher(aesKey)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
mode := cipher.NewCBCDecrypter(block, ivBytes)
|
||||
mode.CryptBlocks(cipherText, cipherText)
|
||||
cipherText, err = app.pkcs7Unpaid(cipherText, block.BlockSize())
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
err = json.Unmarshal(cipherText, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
if result.Watermark.AppID != app.AppId {
|
||||
return result, errors.New("app id not match")
|
||||
}
|
||||
return result, nil
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// UserPhone 请求参数
|
||||
type UserPhone struct {
|
||||
SessionKey string `json:"session_key"`
|
||||
EncryptedData string `json:"encrypted_data"`
|
||||
Iv string `json:"iv"`
|
||||
}
|
||||
|
||||
// UserPhoneResult 返回参数
|
||||
type UserPhoneResult struct {
|
||||
PhoneNumber string `json:"phoneNumber"` // 用户绑定的手机号(国外手机号会有区号)
|
||||
PurePhoneNumber string `json:"purePhoneNumber"` // 没有区号的手机号
|
||||
CountryCode string `json:"countryCode"` // 区号
|
||||
Watermark struct {
|
||||
AppID string `json:"appid"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
} `json:"watermark"`
|
||||
}
|
||||
|
||||
// UserPhone 解密手机号信息
|
||||
func (app *App) UserPhone(param UserPhone) (result UserPhoneResult, err error) {
|
||||
aesKey, err := base64.StdEncoding.DecodeString(param.SessionKey)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
cipherText, err := base64.StdEncoding.DecodeString(param.EncryptedData)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
ivBytes, err := base64.StdEncoding.DecodeString(param.Iv)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
block, err := aes.NewCipher(aesKey)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
mode := cipher.NewCBCDecrypter(block, ivBytes)
|
||||
mode.CryptBlocks(cipherText, cipherText)
|
||||
cipherText, err = app.pkcs7Unpaid(cipherText, block.BlockSize())
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
err = json.Unmarshal(cipherText, &result)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
if result.Watermark.AppID != app.AppId {
|
||||
return result, errors.New("app id not match")
|
||||
}
|
||||
return result, nil
|
||||
}
|
Loading…
Reference in new issue