royalrick / weapp

微信小程序服务端 SDK (for Golang)
https://pkg.go.dev/github.com/medivhzhan/weapp/v3
Apache License 2.0
1.47k stars 281 forks source link

解密手机号接口报错 #65

Open EthanChenLi opened 3 years ago

EthanChenLi commented 3 years ago

操作系统:win10 golang版本:1.14.1

正确传入 sessionkey , encrypted_data,iv 返回以下内容

invalid character '¶' looking for beginning of value
royalrick commented 3 years ago

先调用登陆接口,再进行解密操作。顺序反过来就会报错;

EthanChenLi commented 3 years ago

另外微信解密用户信息似乎不再返回openid了(官方文档也提示不返回了)。 DecryptUserInfo() 该方法的openid应该是拿不到了

royalrick commented 3 years ago

image 看了下文档,仍然包含呢;

JiajunDou commented 3 years ago

/root/go/pkg/mod/github.com/medivhzhan/weapp/v3@v3.3.3/encrypt/cbc.go:59 (0x6dc044) (CBC).Decrypt: cbc.iv = cbc.iv[:size] /root/go/pkg/mod/github.com/medivhzhan/weapp/v3@v3.3.3/decrypt.go:28 (0x6dc88e) (Client).DecryptUserData: return encrypt.NewCBC(rawIV, key, cipher).Decrypt() /root/go/pkg/mod/github.com/medivhzhan/weapp/v3@v3.3.3/decrypt.go:50 (0x6dc951) (*Client).DecryptMobile: raw, err := cli.DecryptUserData(sessionKey, encryptedData, iv)

生产环境中将近1/4报这个错 这个是什么原因?

getUserInfo已经被抛弃了 你手册没有仔细看

royalrick commented 3 years ago

报错的原因就是因为你先调用的获取手机号,再对用用户调用的登陆接口。顺序反了;

royalrick commented 3 years ago

getUserInfo确实被取消了

voidint commented 2 years ago

官方文档中描述的获取手机号的接口发生了变化,目前的sdk好像没法拿到这个信息了。

royalrick commented 2 years ago

@voidint 新版本v3.6.3已经增加,使用方式: cli.NewPhonenumber().GetPhoneNumber