주로 다음 구현 단계 :
1. 도메인 이름을 바인딩하십시오
먼저 WeChat 공개 플랫폼에 로그인하고 "공개 계정 설정"의 "기능 설정"을 입력하여 "JS 인터페이스 보안 도메인 이름"을 작성하십시오. (특별 알림은 http 또는 https를 추가 할 필요가 없습니다. 손실을 입었습니다).
2. 페이지는 JS 파일을 가져옵니다
<script src = "http://res.wx.qq.com/open/js/jweixin-1.0.js"> </script>
<script src = "https://res.wx.qq.com/open/js/jweixin-1.0.js"> </script>
3. 구성 인터페이스를 통해 구성을 확인하십시오
wx.config ({debug : true, // debug mode, debug mode, 모든 API의 반환 값은 클라이언트에서 경고됩니다. 전달 된 매개 변수를 보려면 PC 쪽에서 열 수 있으려면 매개 변수 정보가 로그를 통해 인쇄 될 수 있으며 PC 쪽에만 인쇄 될 것입니다. 비 CESTR : '', // 필수 서명 서명으로 생성 된 임의의 문자열 : '', // 필수, 서명은 부록 1 JSAPILIST : [] // 사용할 JS 인터페이스 목록에 표시되고 모든 JS 인터페이스가 부록 2}에 나열됩니다);4. 준비된 인터페이스 처리를 통해 성공적으로 확인했습니다
wx.ready (function () {// 세부 코드});5. 오류 인터페이스를 통해 검증이 실패했습니다
wx.error (function (res) {});자세한 페이지 코드
<cript> // wechat 공유 순간 $ (function () {/*** 사용자는 wechat circle에 공유하기 위해 클릭하고 인터페이스 인터페이스를로드하고 **********/var url = wind URL : "<%= basepath%>/lottery/sharetofriend.action? url ="+url, type : "post", async : true, cache : false, datatype : "json", success : function (data) {wx.config ({debug : false, appid : ''wx2948dfef9ef421ee ', timestamp : data.timestamp : timestamp : timestamp : timestamp : timestamp : Noncest : noncest, 서명 : data.signature, jsapilist : [ 'checkjsapi', 'onmenusharetimeline', 'onmenushareappmessage'}); wx.checkjsapi ({jsapilist : [getlocation ','onmenusharetimeline ','onmenushareappmessage '], function (res) {//alert(res.errmsg);}}; '<%= basepath%>/lottery/lottery.action? lottery.id = $ {lottery.id}', imgurl : '<%= basepath%>/quess/qjc/img/start.png', trigger (res) {// Alert ( '사용자 클릭으로 친구에게 보낸다'); 잭팟 ~~ '); // $ .ajax ({url : "<%= basepath%>/lottery/rewardplaycount? {openid} & lotteryid = $ {lottery.id} & shareType = friend", "post" function (data) {}}; '<%= basepath%>/lottery/lottery.action? lottery.id = $ {lottery.id}', imgurl : '<%= basepath%>/quess/qjc/img/start.png', trigger : function (res) {// moments에 공유하기 위해 사용자 클릭 : {res) 잭팟 ~~ '); // $ .ajax ({url : "<%= basepath%>/lottery/rewardplaycount? {openid} & lotteryid = $ {lottery.id} & shareType = friendcircle", "post", Async : "jonty :" 함수 (res) {res. })); </스크립트>자바 배경 조치 코드 :
// weChat 공유 공개 void sharetofriend () {httpservletrequest request = servletactionContext.getRequest (); String timestamp = sha1util.gettimestamp (); // timeStamp String noncest = wxconfig.getuuid (); // random String, 32 비트 string url = request.getParameter ( "URL")를 넘지 않습니다. 문자열 시그니처 = wxConfig.getSignature ( "appid", "app_secret", URL, 타임 스탬프, 비 CESTR); request.setAttribute ( "타임 스탬프", 타임 스탬프); request.setAttribute ( "비정부", 비 시체); request.setattribute ( "url", url); request.setAttribute ( "서명", 서명); WXJSSDK 결과 = 새로운 WXJSSDK (타임 스탬프, 비 시사, 서명, URL); commonutil.returnmsg (servletactionContext.getResponse (), new Gson (). tojson (result)); } wxconfig.java 코드
"> // jsapi_ticket public final 정적 문자열 weixin_jsapi_ticket_url ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=access_token&type=jsapi "; // access_token public string getAccestokes getAccestake appsecret) {ac httputil.get (url); new typetoken <string, object >> () .gettype (); accesstokeninfo.get ( "ac "errcode : {} :"+accesstokeninfo.get ( "errcode")+"ervermsg :"+accesstokeninfo.get ( "errmsg")}}}}; mapticket.get (ticket = httputil.weixin_host_api+"/cgi-bin/ticke/getticket? {}. getType (); 객체> ticketInfo = the tiret {ticket = ticketinfo.get ( "ticket"); logger.info (JSAPI_TICKET : "+ticket+"; "+expires_in) {jsonexception e); errcode : {} : "+ticketinfo.get ("errcode ")+"errmsg : {} : "+ticketinfo.get ("errmsg "));}} 반환 티켓;} // 랜덤 String UUID public string getUuid () {String UUID = uuid.randomuuid (). trim (). replaceall ( "-", ""); getJsapiticket (AccessToken); 문자열 : "+signValue); //이 서명.이 서명. 주로 wechat js를로드하는 데 주로 사용됩니다. 위의와 혼동하지 마십시오. 문자열 서명 = sha1util.getsha1 ((signvalue)); logger.info ("wechat js-sdk 권한 확인 서명 : "+서명); reture;};또한 프로젝트에 사용 된 Sha1util.java 및 Md5util.java는 플랫폼에서 직접 다운로드 할 수 있습니다.