1, a method to solve:
@Controller @requestmapping ("Jssdk") Public classWexinjssdkcontroller {@AutowiredPrivateWxmpservice Wxmpservice; @RequestMapping (Value= "/config", method =requestmethod.get) @ResponseBody Publicwxjsapisignature wxjssdkconfig (httpservletrequest request,string url) {Try{wxjsapisignature wxjsapisignature=wxmpservice.createjsapisignature (URL); returnwxjsapisignature; } Catch(wxerrorexception e) {return NULL; } } }
Front Page Use:
/*Initialize JSSDK*/$.get ("${basepath}/jssdk/config.do", {url:window.location.href},function(data,status) {if(Status = = "Success") {wx.config ({debug:false,//turn on debug mode, call the return value of all the APIs will be on the client alert, to see the incoming parameters can be opened on the PC side, the parameter information will be typed through log, only on the PC side will be printed. AppId:data.appId,//mandatory, unique identification of the public numberTimestamp:data.timestamp,//required, time stamp for signature generationNONCESTR:DATA.NONCESTR,//required, generate a random string of signaturesSignature:data.signature,//required, signature, see Appendix 1Jsapilist: [' chooseimage ', ' uploadimage ', ' downloadimage ', ' previewimage ']//must fill in, need to use the JS interface list, all JS interface list See Appendix 2 }); Wx.ready (function(){ //layer.msg ("JSSDK initialization succeeded"); //after the config information is validated, the Ready method is executed, and all interface calls must be completed by the Config interface, and config is a client-side asynchronous Operation . //so if you need to invoke the relevant interface when the page loads, you must put the relevant interface in the ready function to make sure that it is executed correctly. For interfaces that are invoked when a user fires, they can be called directly and do not need to be placed in the ready function. }); Wx.error (function(res) {//Config information validation failure will execute the error function, such as the expiration of the signature causes validation to fail, the specific error message can open config Debug mode view, //It can also be viewed in the returned res parameter, where the signature can be updated for spa. layer.msg (RES); }); } },"JSON");
Use of Weixin-java-tools JSSDK