-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
小程序请求有时会出现 Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ #359
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
https://www.cnblogs.com/guansixu/articles/6484872.html 楼上遇到问题的各位请参考此文,不知是否有帮助 |
@binarywang 感谢回复。我这边遇到的问题和你分享的文章相似。 回头翻了一下小程序开发手册,发现开发过程中忽略了下面这段注意事项。 修改了调用wx.login顺序后,问题解决。 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
解密手机号的时候,遇到了相同的问题,原因是用固定的 session_key + encryptedData+ iv 解密,但是encryptedData 或者 iv 可能是一次性的,解密完之后就不能再用了 |
This comment has been minimized.
This comment has been minimized.
确认下前后端传递的参数有没有做UrlEncode/UrlDecode,因为encryptedData里会包含特殊字符在传递参数时被转义,可能服务器端实际拿到的参数encryptedData并不是前端实际获取到的值,导致SDK调用微信相应接口时无法解密而报错,只要保证前端实际获取到的encryptedData和服务器端调用SDK时传入的encryptedData一致就不会报错的,SDK中方法并无问题;建议让前后台都打印下日志,看下服务端最终使用的参数值是否还是前端获取到的原始值呢。 重要:有朋友反映按照以上描述处理后还是会偶尔出现这个解密问题,那么可能就是前后端没有协同好了,忽略了每次调用wx.login时微信都会刷新sessionkey,可能造成后台使用了旧的/过期的sessionkey去解密而失败,一般开发小程序时有一个原则,前端只要调用wx.login就必须通知后台使用最新的code刷新sessionkey!所以正确的做法应该是:
PS:wx.request对GET/POST传递字符串参数时会自动做encodeURIComponent,SpringBoot某些场景下form表单参数是会自动做UrlDecode的... |
多谢大佬,就是特殊字符被转义了 |
多谢大佬,我懂了 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
原因是前端的authcode码失效了
---原始邮件---
发件人:"jiaoqianjin"<[email protected]>
发送时间:2021年1月30日 星期六 上午11:43
收件人:"Wechat-Group/WxJava"<[email protected]>
抄送:"小熊羔子"<[email protected]>;"Comment"<[email protected]>
主题:Re: [Wechat-Group/WxJava] 小程序请求有时会出现 Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ (#359)
我也遇到这个问题了,是WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr)这个方法返回值是乱码,传入的参数没问题
您好,请问这个问题您当时是怎么解决的,我现在也遇到了传入参数没问题,返回参数乱码
—
You are receiving this because you commented.
Reply to this email directly,view it on GitHub, orunsubscribe.
|
@weiqilong 可以爬一下楼,问题解决方案都在上面,可以一步一步排查。 |
我也遇到偶尔解密失败的问题,看完大佬们的回答,调查后发现是顺序问题。前端先调用了getUserInfo,再调用wx.login,拿着旧的加密信息和新的session去解密了。。 |
我亲自测试了, session_key + encryptedData+ iv 可以重复使用postman拿到手机号码,并不是你说的一次性。 |
前端获取到用户手机号信息,然后打印,接着使用postman调用后端接口,由后端进行用户手机号信息解密。 每个人的回答我都看了,但是依然没懂这个错误到底是什么原因···能否告知下 |
This comment was marked as spam.
This comment was marked as spam.
我这边遇到了线下可以获取到用户信息,到线上就报错,错误信息提示中如下列: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ 代码层面:(getPhoneNoInfo不报错,getUserInfo会报上述的错) |
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.google.gson.Gson.fromJson(Gson.java:773)
at cn.binarywang.wx.miniapp.bean.WxMaUserInfo.fromJson(WxMaUserInfo.java:23)
at cn.binarywang.wx.miniapp.api.impl.WxMaUserServiceImpl.getUserInfo(WxMaUserServiceImpl.java:41)
The text was updated successfully, but these errors were encountered: