請問wx.config配置到哪裡?還有就是timestamp,nonceStr,signature這三個參數如何獲取的呢?有沒有代碼接口呢?目前在做微信語音播放這塊,好多都是自學,有沒有相同經驗可以借鑒下,謝謝!!!
token = CommonUtil.getToken(appid, appsecret);
// jsapi ticket
jsapi_ticket = SignUtil.getJsapi_ticket(token.getAccessToken());
// JSSDK - for user center upload
signature = SignUtil.getJsSDKSignature(jsapi_ticket, nonceStr, timestamp, url_1);
nonceStr你寫一個字符串,我在項目中寫的和微信中配置的token是一致的。
timestamp=1417504553(我的timestamp賦值內容)
getJsapi_ticket的實現方法:
public static String getJsapi_ticket(String access_token){
String ticket = "";
String requestUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+access_token+"&type=jsapi";
String requestMethod = "GET";
String outputStr = null;// JSONObject.fromObject(new TokenJson(access_token)).toString();
// 先從線程中取值,如果取不到,說明沒有使用線程,再利用這個方法獲取
// 因為發送信息等操作,都是調用的這個方法,所以在這裡進行處理一下吧
JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, requestMethod, outputStr);
if (null != jsonObject) {
ticket = jsonObject.getString("ticket");
}
return ticket;
}
附上getJsSDKSignature的實現方法:
public static String getJsSDKSignature(
String jsapi_ticket,String noncestr, String timestamp,
String url) {
String string1 = "jsapi_ticket="+jsapi_ticket;
string1 += "&noncestr=" + noncestr;
string1 += "×tamp=" + timestamp;
string1 += "&url=" + url;
String ciphertext = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
// 對接後的字符串進行sha1加密
byte[] digest = md.digest(string1.toString().getBytes());
ciphertext = byteToStr(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return ciphertext;
}
你獲得各個數據值之後,可以用微信提供的網上驗證工具驗證是否正確
http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign