WeChat 공유 인터페이스 개발의 일부 작은 단계, 특정 컨텐츠는 다음과 같습니다.
1. 확인을 위해 인터페이스 정보를 구성합니다
코드는 다음과 같습니다.
/** * Jump to access the unauthenticated address * * @param request * @return Login page * @throws Exception */ @RequestMapping(value = "/checkWxDomainUrl", method = RequestMethod.GET) public void checkWxDomainUrl(HttpServletRequest request) throws Exception { try { // After the developer submits the information, the WeChat server will send a GET request to the 채워진 서버 주소 URL 및 GET 요청은 매개 변수 문자열 서명 = request.getParameter ( "signature"); // wechat 암호화 서명 (Token, Timestamp, Nonce.) String timestamp = request.getParameter ( "timeStamp"); // timestamp string nonce = request.getParameter ( "noneTparameter"; request.getParameter ( "echostr"); // random string // 사전 토큰, timestamp, nonce string [] params = new String [] {토큰, 타임 스탬프, nonce}; Arrays.SORT (PARAMS); // SHA1 암호화 문자열에 대한 3 개의 매개 변수 문자열 splice string string cleartext = params [0] + params [1] + params [2]; 문자열 알고리즘 = "SHA-1"; 문자열 부호 = 새 String (hex.encodeHex (messageDigest.getInstance (알고리즘) .Digest ((clareText) .getBytes ()), true); // 저자는 서명으로 암호화 된 문자열을 얻습니다. }} catch (예외 e) {e.printstacktrace (); }}2.JS 구성
3. 공유 페이지 JS 매개 변수를 가져 와서 캐시에 추가 할 토큰 및 티켓을 가져옵니다.
/** * 메소드 이름 : getwxConfig </br> * 자세한 설명 : weChat 구성 정보 가져 오기 </br> * 개발자 : gy * @param request * @return 반품 값의 의미를 설명 * @throws이 예외의 조건을 설명 */@override public map <string, 객체> getwxconfig (httpervletrequest 요청) {map <string, 객체> rethmat <string, 객체> 개체> (); 문자열 appid = wxconfigure.getAppid (); // 필수, 공식 계정 문자열의 고유 식별자 requestUrl = request.getRequestUrl (). toString (); 문자열 accessToken = null; 문자열 jsapiticket = null; 문자열 url = ""; String timestamp = long.tostring (System.CurrentTimeMillis () / 1000); // 필수, 시그니처 타임 스탬프 문자열을 생성하지 않음. // 서명 랜덤 문자열을 생성하십시오. // 여기에서 캐시에서 먼저 쿼리를하고 호출 인터페이스 쿼리 캐시에서 유효한 액세스 시간을 설정해야합니다. // redistemplate.opsForValue (). getOperations (). delete (prefix); // AccessToken = (String) RedistemPlate.OpSforValue (). get (prefix); Token AccessTokenFromedis = getAccessTokenFromedis (); accessToken = accessTokenFromedis.getAccessToken (); if (accessTokenfromedis.getAccessToken ()! = null) {jsapiticket = (string) redistemplate.opsforValue (). get (prefixticket); if (jsapiticket == null) {url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "& type = jsapi"; jsonobject json = httprequest (url, "get", null); if (json! = null) {jsapiticket = json.getstring ( "ticket"); redistemplate.opsforValue (). set (prefixticket, jsapiticket); redistemplate.expire (prefixticket, integer.parseint (wxconfigure.getexpiretime ()), timeUnit.seconds); }}} string signature = ""; // 여기서 매개 변수 이름은 모두 소문자 여야하며 문자열 부호 = "jsapi_ticket =" + jsapiticket + "& noncest =" + noncest + "× tamp =" + timestamp + "& url =" + requestUrl; try {messageDigest crypt = messageDigest.getInstance ( "SHA-1"); crypt.reset (); crypt.update (sign.getBytes ( "UTF-8")); Signature = BytetoHex (crypt.digest ()); } catch (nosuchalgorithmexception e) {e.printstacktrace (); } catch (UnsupportedEncodingException e) {e.printstacktrace (); } ret.put ( "appid", appid); ret.put ( "타임 스탬프", 타임 스탬프); ret.put ( "비정규", 비 시스트); ret.put ( "서명", 서명); Ret Ret; }/** * 메소드 이름 : bytetoHex </br> * 세부 설명 : 문자열 암호화 보조 메소드 </br> * 개발자 : gy </br> * @param hash * @return이 예외 */private static string (formal bypanter)에 대한 조건에 대한 @throws 설명을 설명합니다. for (byte b : hash) {formatter.format ( "%02x", b); } 문자열 결과 = formatter.toString (); formatter.close (); 반환 결과; } / ** * redis에서 AccessToken을 얻고 키의 문자열 값을 지정합니다. 문자열 atsessToken = (String) RedistemPlate.OpSforValue (). get (wxConfigure.getTokenKey ()); if (null! = esthestoken &&! "". Token.setAccessToken (AssessToken); 복귀 토큰; } else {token = commentwxutil.getToken (wxConfigure.getAppid (), wxConfigure.getSecret ()); redistemplate.opsforValue (). set (wxConfigure.getTokenKey (), token.getAccessToken ()); redistemplate.expire (wxconfigure.gettokenkey (), integer.parseint (wxconfigure.getexpiretime ()), timeUnit.seconds); 복귀 토큰; }}4. 페이지 관련 JS 소개
<script type = "text/javaScript"src = "http://res.wx.qq.com/jsweixin-1.0.js"> </script> <script type = "text/javaScript" src = "https://res.wx.qq.com/open/js/jweixin-1.0.js"> </script> <script type = "text/javascript"> // wechat 정보 및 호출 구성 // wechat 정보 및 통화 구성 var sign = $ ( "#signature"); var appid = $ ( "#appid"). val (); var appid = $ ( "#appid"). val (); var timestamp = $ ( "#timestamp"). val (); var noncestr = $ ( "#noncestr"). val (); var userId = $ ( "#userId"). val (); var productName = 1; 경고 (서명); wx.config ({debug : false, appid : appid, timestamp : timestamp, noncestr : noncest, signature : [ 'onmenusharetimeline', 'onmenushareAppmessage', 'onmenushareqq', 'onmenushareweibo', 'onmenushareweibo'); wx.ready (function () {var isok = true; wx.checkjsapi ({jsapilist : [ 'onmenusharetimeline'], fail : forne (res) {alert ( "wechat 버전이 너무 낮고 친구와 공유되는 기능이 지원되지 않습니다!"); isok = false;})); // "Moments to Moments"버튼의 클릭 상태를 가져 와서 콘텐츠 인터페이스 공유 인터페이스 WX.ONMENUSHARETIMELENE ({제목 : '파트 :'Part 6 : WeChat Public Platform Development의 실제 Java 버전에 대한 WeChat 공개 계정 메뉴를 사용자 정의하는 방법 ', DESC :'파트 6 : WeChat Public Development의 실용적인 Java 버전을 사용자 정의하는 방법 ', 링크' 'http://4d536256.ngrok.io/login', imgurl : 'http://busc.4ggogo.com/media/media/img/home-show-a.png', success : res) {alert (json.stringify (res)); $ .ajax ({type : "get", url : 'insertCollectShare', data : {userId : userId,}, datatype : "json", async : false, success : function (data) {alert (200);}, error : function (data) {var rurl = xhr.getResponsheader ( 'contentpath'); }); *// 사용자는 공유/ *window.location.href = insertCollectShare = ' + userId}를 확인합니다. WX.ONMENUSHAREAPPMESSAGE ({제목 : '파트 7 : WeChat Public Platform 개발에서 WeChat 사용자의 기본 정보를 얻는 방법', // Title Desc 공유 : "7 부 : WeChat 사용자의 기본 정보를 얻는 방법 ' 'http://busc.4ggogo.com/media/media/media/img/home-show-a.png', // 아이콘 유형 : // '링크', // 공유 유형, 음악, 비디오 또는 링크, 기본값 링크}; WeChat Public Platform Development의 실용적 Java 버전 메뉴 ', // 제목 공유 제목 DESC :'Part 6 : WeChat Public Public Development의 실제 Java 버전에 대한 WeChat 공개 계정 메뉴를 사용자 정의하는 방법 ', // 공유 설명 링크 :'http://4d536256.ngrok.io/login ', // link imgurl : // link imgurl : // 'http://busc.4ggogo.com/media/media/media/img/home-show-a.png', // 아이콘 성공 : function () {// 사용자가 공유를 확인한 후 실행 된 콜백 함수}, cance () {// 사용자 cancels}}) 인터페이스 wx.onmenushareweibo ({title : 'tencent weibo title 공유', // 제목 공유 desc : 'tencent weibo description weibo description', // 공유 설명 링크 : 'http://4d536256.ngrok.io/login', // share link imgurl : 'http://busc.4ggogo.com/media/media/media/img/home-show-a.png', // 아이콘 성공 : function () {// 콜백 함수 공유 확인}, cance () {// 콜백 함수 공유 후}}; WX.ONMENUSHAREQZONE ({제목 : 'QQ 공간 공유 제목 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111오까지 공유 :'QQ 공간 설명 공유 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 'http://4d536256.ngrok.io/login', imgurl : 'http : //busc.4ggogo.com/media/media/img/home-show-a.png', // 아이콘 성공 : function () {// 사용자가 공유 기능을 확인한 후 콜백 함수를 확인한 후 (). 사용자는 공유}});참고 : 전송 된 경로는 구성된 도메인 이름 경로입니다. 그렇지 않으면 호출 할 수 없으며 이미지 크기가 300K보다 클 수 없습니다.
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.