关于网友提出的“微信jssdk 问题。 配置wxconfig 一直报{errmsg:config:ok}{errmsg:config:invalid signat} 请指点”问题疑问,本网通过在网上对“微信jssdk 问题。 配置wxconfig 一直报{errmsg:config:ok}{errmsg:config:invalid signat} 请指点”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:微信jssdk 问题。 配置wxconfig 一直报{errmsg:config:ok}{errmsg:config:invalid signat} 请指点
描述:
微信jssdkinvalid signatureconfig:ok
现在确认:1、生成的签名更微信提供的签名是一致的:如下图

2、确定nonceStr 也符合书写条件。如下图:

3、Url 不太清楚 是不是符合条件:http://weixin.sinotruk.com/location/default.aspx
是用: url = HttpContext.Current.Request.Url.ToString(); 动态获取的
用的一下方法处理的: (同时附上 签名的方法)

4、也缓存保存了Access_Token、Jsapi_Ticket
现在微信端打开就报{errmsg:config:ok} debug为true的时候就是{errmsg:config: invalid signature}。真心找不到还有哪里是错误的了,请大神们指点先,或者讨论下吧。谢谢了
真的木有思路了。。。。。憋了两天了。。求指点
解决方案1:
我的已经解决,贴出我的所有代码,希望能对有问题的同学有帮助,勿喷,谢谢!
1、获取JsApiTicket,请获取后保存到数据库中,方便后续操作!
private static final String JSAPI_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
public String getJsApiTicketByWX(String token) {
String jsAPITicktUrl = JSAPI_TICKET_URL + "&access_token=" + token;
String jsAPITick = null;
try {
StringBuffer sTotalString = getJsonStringByConnection(jsAPITicktUrl);
JSONObject jsonObject = JSONObject.fromObject(sTotalString.toString());
jsAPITick = jsonObject.getString("ticket");
logger.info("access_token【" + jsAPITick + "】");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return jsAPITick;
}
protected StringBuffer getJsonStringByConnection(String urlString) throws MalformedURLException, IOException {
logger.debug("urlString:" + urlString);
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream urlStream = connection.getInputStream();
connection.setConnectTimeout(2000);
connection.setReadTimeout(5000);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlStream,
Charset.forName(BaseRemoteService.UTF_8)));
StringBuffer sTotalString = new StringBuffer();
String sCurrentLine = "";
while ((sCurrentLine = bufferedReader.readLine()) != null) {
sTotalString.append(sCurrentLine);
}
bufferedReader.close();
connection.disconnect();
return sTotalString;
}
2、生成JsSDKConfig所需要参数
@Controller
public class WxJsSDKWechatCtrl {
private static Logger logger = LoggerUtil.getLogger();
@Resource
private UserService userService;
@Resource
private WechatTencentService wechatTencentService;
@RequestMapping(value = "/wx/getJsSDKConfig")
@ResponseBody
public JsSDKConfig getJsSDKConfig(HttpServletRequest request, String targetUrl) {
//String url = CommonsUtils.getHttpWebappName();
if (StringUtils.isBlank(targetUrl)) {
throw new WechatBusinessException("jsapiTicket获取失败,当前url为空!!");
}
int index = targetUrl.indexOf("#");
if (index > 0) {
targetUrl = targetUrl.substring(0, index);
//targetUrl = targetUrl.toLowerCase();
logger.debug("targetUrl:" + targetUrl);
}
String originId = CookieUtil.getOriginIdByCookie_Exception(request);
//从数据库获取
WechatAccount account = userService.getWechatAccountByOriginId(originId);
List tokens = wechatTencentService.getTokenListByOriginId(originId);
if (tokens == null || tokens.size() == 0) {
throw new WechatBusinessException("jsapiTicket获取失败!!");
}
WeAccessToken weAccessToken = tokens.get(0);
if (weAccessToken == null || StringUtils.isBlank(weAccessToken.getJsApiTicket())) {
throw new WechatBusinessException("jsapiTicket获取失败!!");
} else {
logger.debug("jsApiTicket:" + weAccessToken.getJsApiTicket());
}
Map ret = JsSDKSign.sign(weAccessToken.getJsApiTicket(), targetUrl);
JsSDKConfig jsSDKConfig = new JsSDKConfig();
jsSDKConfig.setAppId(account.getAppId());
jsSDKConfig.setNonceStr(ret.get("nonceStr"));
jsSDKConfig.setTimestamp(ret.get("timestamp"));
jsSDKConfig.setSignature(ret.get("signature"));
logger.debug(jsSDKConfig.toString());
return jsSDKConfig;
}
}
public class JsSDKConfig {
public String appId;
public String timestamp;
public String nonceStr;
public String signature;
public static final String JS_API = "onMenuShareTimeline,onMenuShareAppMessage,onMenuShareQQ,onMenuShareWeibo,startRecord,stopRecord,onVoiceRecordEnd,playVoice,pauseVoice,stopVoice,onVoicePlayEnd,uploadVoice,downloadVoice,chooseImage,previewImage,uploadImage,downloadImage,translateVoice,getNetworkType,openLocation,getLocation,hideOptionMenu,showOptionMenu,hideMenuItems,showMenuItems,hideAllNonBaseMenuItem,showAllNonBaseMenuItem,closeWindow,scanQRCode,chooseWXPay,openProductSpecificView,addCard,chooseCard,openCard";
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
public String[] getJsApiList() {
return JS_API.split(",");
}
@Override
public String toString() {
return "appId:" + this.appId + "\n" + "timestamp:" + this.timestamp + "\n" + "nonceStr:" + this.nonceStr + "\n"
+ "signature:" + this.signature + "\n" + "JS_API:" + JS_API;
}
}
public class JsSDKSign {
public static Map sign(String jsapi_ticket, String url) {
Map ret = new HashMap();
String nonce_str = create_nonce_str();
String timestamp = create_timestamp();
String string1;
String signature = "";
//注意这里参数名必须全部小写,且必须有序
string1 = "jsapi_ticket=" + jsapi_ticket + "&n>
解决方案2:
{errmsg:config:ok}是debug的正常返回
我的页面js如下:
var url = '${rc.contextPath}/wx/getJsSDKConfig';
var targetUrl = window.location.href;
///targetUrl = encodeURIComponent(encodeURIComponent(targetUrl));
//targetUrl = targetUrl.split('#')[0]
base.ajaxAsync('post',url,{'targetUrl':targetUrl},function(config){
if(!window.jsApiList){
window.jsApiList = config.jsApiList;
}
wx.config({
debug: false,
appId: config.appId,
timestamp: config.timestamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: window.jsApiList
});
wx.error(function(res) {
$.scojs_message(res.errMsg, $.scojs_message.TYPE_ERROR);
});
})
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
WeixinJSBridge.call('showToolbar');
WeixinJSBridge.call('showOptionMenu');
});
wx.ready(function () {
window.shareData = {
"imgUrl" : $('#giftBoxShareImgUrl').val(),
"timeLineLink" : $('#giftBoxShare').val(),
"sendFriendLink" : $('#giftBoxShare').val(),
"tTitle" : "${(activity.name)!}",
"tContent" : "${(activity.news.summary)!}",
"fTitle" : "${(activity.name)!}",
"fContent" : "${(activity.news.summary)!}",
};
wx.onMenuShareAppMessage({
title: window.shareData.tTitle,
desc: window.shareData.tContent,
link: window.shareData.sendFriendLink,
imgUrl: window.shareData.imgUrl,
success: function (res) {
$.scojs_message('已分享',$.scojs_message.TYPE_OK);
},
fail: function (res) {
$.scojs_message(JSON.stringify(res),$.scojs_message.TYPE_ERROR);
}
});
wx.onMenuShareTimeline({
title: window.shareData.tTitle,
link: window.shareData.timeLineLink,
imgUrl: window.shareData.imgUrl,
desc: window.shareData.tContent,
success: function (res) {
$.scojs_message('已分享',$.scojs_message.TYPE_OK);
},
fail: function (res) {
$.scojs_message(JSON.stringify(res),$.scojs_message.TYPE_ERROR);
}
});
});
解决方案3:
我发一下我的分享,希望对你有帮助,dataUrl和imgurl你自己填写吧
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '@ViewData["appId"].ToString()', // 必填,公众号的唯一标识
timestamp: @ViewData["timeStamp"], // 必填,生成签名的时间戳
nonceStr: '@ViewData["nonceStr"].ToString()', // 必填,生成签名的随机串
signature: '@ViewData["signature"].ToString()',// 必填,签名,见附录1
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage'
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
// 发送给好友
wx.onMenuShareTimeline({
title: '【乐淘精品】发红包啦', // 分享标题
link:, // 分享链接
imgUrl:, // 分享图标
success: function () {
alert("success");
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
alert("cancel");
}
});
// 分享到朋友圈
wx.onMenuShareAppMessage({
title: '【乐淘精品】', // 分享标题
desc: '【乐淘精品】发红包啦,小伙伴们赶快来', // 分享描述
link:, // 分享链接
imgUrl: ,// 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
//alert("success");
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
//alert("cancel");
}
});
});
以上介绍了“微信jssdk 问题。 配置wxconfig 一直报{errmsg:config:ok}{errmsg:config:invalid signat} 请指点”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1413792.html