JAVA code to generate the signature: is the official demonstration of the code, I replace the jsapi_ticket into my own, and then the URL address is my project, through the external URL WeChat server debugging, I am right directly run JAVAapplication generated, don't know where there is a mistake, beg god some directions!
This is done through the run JAVAapplication generated signature and string parameters such as timestamp, is not the same as in the document demonstration:
Signature, d07438b2baf4af91d025f75b7f7dfdeacd39c043
Jsapi_ticket kgt8ON7yVITDhtdwci0qeQsc9UPtToeuNRefrM40_oY6KJntPRrs_yuKp1nPo7l03iFac0wQYOq9LD9 - qaXp1w
Url, http://x5oddnhhiq.proxy.qqbrowser.cc/Demo? Params=value
NonceStr, 5933 a62 c9 fe46-67-4 - a2f6 bec6-86567243
Timestamp, 1472870800
This is the code:
Import the Java. Util. UUID;
import java.util.Map;
import java.util.HashMap;
Import the Java. Util. Formatter;
Import the Java. Security. MessageDigest;
Import the Java. Security. NoSuchAlgorithmException;
Import the Java. IO. UnsupportedEncodingException;
The class Sign {
Public static void main (String [] args) {
String jsapi_ticket="kgt8ON7yVITDhtdwci0qeQsc9UPtToeuNRefrM40_oY6KJntPRrs_yuKp1nPo7l03iFac0wQYOq9LD9 - qaXp1w";
//note that the URL must be dynamic, not hardcode
The String url="http://x5oddnhhiq.proxy.qqbrowser.cc/Demo? Params=value ";
Map
For (Map) Entry Entry: ret. EntrySet ()) {
System. The out. Println (entry. GetKey () + ", "+ entry. GetValue ());
}
};
Public static Map
Map
String nonce_str=create_nonce_str ();
String timestamp=create_timestamp ();
String string1.
String signature="";
//note that this parameter name must be all lowercase, and must be ordered
String1="jsapi_ticket=" + jsapi_ticket +
"& amp; Noncestr="+ nonce_str +
"X tamp=" + timestamp +
"& amp; Url="+ url;
System. The out. Println (string1);
Try
{
MessageDigest crypt=MessageDigest. GetInstance (" SHA - 1 ");
Crypt. Reset ();
Crypt. Update (string1. GetBytes (" utf-8 "));
Signature=byteToHex (crypt. Digest ());
}
The catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
The catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
Ret. Put (" url ", url);
Ret. Put (" jsapi_ticket jsapi_ticket);
Ret. Put (" nonceStr nonce_str);
Ret. Put (" timestamp ", timestamp);
Ret. Put (" signature ", signature);
return ret;
}
Private static String byteToHex (final byte [] hash) {
The Formatter Formatter=new Formatter ();
For (byte b: hash)
{
The formatter. The format (" % 02 x ", b);
}
The String result=formatter. ToString ();
The formatter. Close ();
return result;
}
Private static String create_nonce_str () {
Return UUID. RandomUUID (). The toString ();
}
Private static String create_timestamp () {
Return Long. ToString (System. CurrentTimeMillis ()/1000);
}
}
This is written in the JSP page JS code wx. Config, if use WeChat built-in browser open will play the window errmsg: invalid signature, implore you!!!!! Do not to come out to fuck off...
Wx. Config ({
The debug: true,//open the debug mode, all the API calls return values will alert on the client, if you want to check the incoming parameters, can open the PC, parameter information through the log to type, only when the PC will print,
AppId: 'wx376f4aa02d47e3de',//required, the public, the unique identification of the
Timestamp: '1472870800',//required, the signature of timestamp
NonceStr: '5933 a62 c9 fe46-67-4 - a2f6 bec6-86567243',//required, randomly generated signature string
Signature: 'd07438b2baf4af91d025f75b7f7dfdeacd39c043',//will fill, sign
JsApiList: [' onMenuShareAppMessage,
'onMenuShareTimeline'
]//will fill in, need to use JS interface list
});
CodePudding user response:
No one? Everyone a great god still didn't get up?CodePudding user response:
I use this very convenienthttp://lianjie.mm2018.com/