Use of Weixin-java-tools JSSDK

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.