quyueting 5 gadi atpakaļ
vecāks
revīzija
f8985c3b73

+ 142 - 52
minigame/WebContent/index.html

@@ -15,6 +15,7 @@
     <title>贝蒂斯厨房</title>
     <script src="./js/flexiable.js"></script>
     <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
+	<script src="https://tjs.sjs.sinajs.cn/open/thirdpart/js/jsapi/mobile.js" charset="utf-8"></script>
     <link rel="stylesheet" type="text/css" href="./css/animate.min.css?v=1">
     <link rel="stylesheet" type="text/css" href="./css/music.css?v=2">
     <link rel="stylesheet" type="text/css" href="./css/main.css?v=2">
@@ -222,53 +223,18 @@
             };
         });
     }
-
-    $(function () {
-        $.post("./user/getWxConfigParam?url=https://wx.ttkuaiban.com/minigame/index.html", {}, function(resp) {
-            if (resp.code == 'error') {
-                console.log(resp.code);
-            }else{
-                wx.config({
-                    debug: false,
-                    appId: 'wx749c84daac654e1e',
-                    timestamp: resp.data.timestamp,
-                    nonceStr: resp.data.noncestr,
-                    signature: resp.data.sign,
-                    jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'showOptionMenu', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem']
-                });
-                wx.ready(function(){
-                    const share = {
-                        title: "一秒变大厨,为远方的朋友做道菜吧!",
-                        desc: "",
-                        imgUrl: "https://wx.ttkuaiban.com/minigame/images/share_picture.png",
-                        link: "https://wx.ttkuaiban.com/minigame/index.html",
-                        success: function(res) {
-                            console.log(res)
-                        },
-                        cancel: function() {}
-                    };
-                    wx.onMenuShareAppMessage(share);
-                    wx.onMenuShareTimeline(share);
-                    wx.onMenuShareQQ(share);
-                    wx.onMenuShareQZone(share);
-                    wx.onMenuShareWeibo(share);
-                });
-
-                wx.error(function(res){
-                    console.log(res);
-                });
-            };
-        });
-        
-        //weibo
-        $.post("./user/getWeiboConfigParam?url=https://wx.ttkuaiban.com/minigame/lottery.html", {}, function(resp) {
+    
+    //通过微博进行分享的回调时事件
+    function shareWeibo(msg) {
+    	var url = escape(window.location.href.split('#')[0]);
+        $.post("./user/getWeiboConfigParam?url=" + url, {}, function(resp) {
     		if (resp.code == 'error') {
     			console.log(resp.code);
     		}else{
     			window.WeiboJS.init({
     			    'appkey' : resp.data.appkey,
-    			    'debug': true,
-    			    'timestamp': resp.data.timestamp,
+    			    'debug': false,
+    			    'timestamp': parseInt(resp.data.timestamp),
     			    'noncestr': resp.data.noncestr,
     			    'signature': resp.data.sign,
     			    'scope': [
@@ -278,6 +244,7 @@
     			        'checkAvailability',
     			        'setBrowserTitle',
     			        'openMenu',
+    			        'menuItemAvailable',
     			        'setMenuItems',
     			        'menuItemSelected',
     			        'setSharingContent',
@@ -289,19 +256,142 @@
     			        'apiFromTheFuture'
     			    ]
     			}, function(ret){
-    			    alert('init done\n' + JSON.stringify(ret));/*DEBUG*/
+    				$("#cover").show();
+    				var shareTitle = "一秒变大厨,为远方的朋友做道菜吧!";
+    				var shareImg = "https://wx.ttkuaiban.com/minigame/images/share_picture.png";
+					WeiboJS.invoke("setSharingContent", {
+						title: shareTitle,
+						desc: msg,
+						icon: shareImg
+					}, function(e) {
+// 						alert("设置分享内容成功:" + JSON.stringify(e));
+					});
+// 					WeiboJS.invoke("setMenuItems", {
+// 						 menus : ["shareToWeibo", "follow"],
+// 						content : "我是默认文案"
+// 			            }, function(params){
+// // 			            	alert("setMenuItems 返回数据:" + JSON.stringify(params));
+// 			        });
+					WeiboJS.on("menuItemSelected", function(params){
+// 						alert("menuItemSelected:" + JSON.stringify(params));
+						if (!params.hasOwnProperty("error")) {
+							window.location.href = "https://wx.ttkuaiban.com/minigame/lottery.html";
+						}
+					});
+// 			     	WeiboJS.invoke("openMenu", {}, function(params){
+// 			     		alert("openMenu 返回数据:" + JSON.stringify(params));
+// 			         });
     			});
-    			
-    			WeiboJS.invoke("setSharingContent", {
-    			    title: "抽奖页面测试标题",
-    			    desc: "抽奖页面测试描述",
-    			    icon: "https://wx.ttkuaiban.com/minigame/images/share_picture.png"
-    			}, function(e) {
-    	            alert("设置分享内容成功:" + JSON.stringify(e));
-    	        });
     		}
         });
-        
+    }
+
+    $(function () {
+    	var shareTitle = "一秒变大厨,为远方的朋友做道菜吧!";
+    	var shareImg = "https://wx.ttkuaiban.com/minigame/images/share_picture.png";
+    	var shareLink = "https://wx.ttkuaiban.com/minigame/index.html";
+    	var ua = navigator.userAgent.toLowerCase();
+    	if (ua.match(/microMessenger/i) == 'micromessenger') {
+    		$.post("./user/getWxConfigParam?url=https://wx.ttkuaiban.com/minigame/index.html", {}, function(resp) {
+                if (resp.code == 'error') {
+                    console.log(resp.code);
+                }else{
+                    wx.config({
+                        debug: false,
+                        appId: 'wx749c84daac654e1e',
+                        timestamp: resp.data.timestamp,
+                        nonceStr: resp.data.noncestr,
+                        signature: resp.data.sign,
+                        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'showOptionMenu', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem']
+                    });
+                    wx.ready(function(){
+                        const share = {
+                            title: shareTitle,
+                            desc: "",
+                            imgUrl: shareImg,
+                            link: shareLink,
+                            success: function(res) {
+                                console.log(res)
+                            },
+                            cancel: function() {}
+                        };
+                        wx.onMenuShareAppMessage(share);
+                        wx.onMenuShareTimeline(share);
+                        wx.onMenuShareQQ(share);
+                        wx.onMenuShareQZone(share);
+                        wx.onMenuShareWeibo(share);
+                    });
+
+                    wx.error(function(res){
+                        console.log(res);
+                    });
+                };
+            });
+        } else if (ua.match(/weibo/i) == 'weibo') {
+        	//weibo
+    		var url = escape(location.href);
+            $.post("./user/getWeiboConfigParam?url=" + url, {}, function(resp) {
+        		if (resp.code == 'error') {
+        			console.log(resp.code);
+        		}else{
+        			window.WeiboJS.init({
+        			    'appkey' : resp.data.appkey,
+        			    'debug': false,
+        			    'timestamp': parseInt(resp.data.timestamp),
+        			    'noncestr': resp.data.noncestr,
+        			    'signature': resp.data.sign,
+        			    'scope': [
+        			        'getNetworkType',
+        			        'networkTypeChanged',
+        			        'getBrowserInfo',
+        			        'checkAvailability',
+        			        'setBrowserTitle',
+        			        'openMenu',
+        			        'menuItemAvailable',
+        			        'setMenuItems',
+        			        'menuItemSelected',
+        			        'setSharingContent',-
+        			        'openImage',
+        			        'scanQRCode',
+        			        'pickImage',
+        			        'getLocation',
+        			        'pickContact',
+        			        'apiFromTheFuture'
+        			    ]
+        			}, function(ret){
+    					WeiboJS.invoke("setSharingContent", {
+    						title: shareTitle,
+    						desc: "",
+    						icon: shareImg
+    					}, function(e) {
+//     						alert("1-设置分享内容成功:" + JSON.stringify(e));
+    					});
+//     					WeiboJS.invoke("setMenuItems", {
+//     						/**微博:1001好友圈:1002
+// 								私信	:1003
+// 								微信好友:1004
+// 								朋友圈:1005
+// 								来往动态:1009
+// 								QQ:1010
+// 								Qzone:1011
+// 								短信:1101
+// 								邮件:1102**/
+// 							 menus : ["1001","1002", "1003", "1004","1005", "1010"],
+// 								content : shareTitle
+// 				            	}, function(params){
+// 				            		alert("setMenuItems 返回数据:" + JSON.stringify(params));
+// 				        		});
+    					//"shareToWeibo", "follow", "shareToMessage", "shareToWeixin", "shareToPYQ", "shareToQQ", "shareToQzone", "openInBrowser", "copyURL"
+    					
+//     					WeiboJS.invoke("menuItemAvailable", {}, function(params){
+//     						      alert("获取的菜单项:" + JSON.stringify(params));
+//     						});
+        			});
+        		}
+            });
+        } else {
+//         	alert('noooooo');
+        }
     })
 </script>
 </body>

+ 5 - 1
minigame/WebContent/js/main.js

@@ -1066,7 +1066,11 @@ function saveText() {
                 var share = msg.data.receiver + "," + msg.data.message;
 
                 //海报页面的微信分享
-                shareWeixin(share);
+                if (ua.match(/MicroMessenger/i) == 'micromessenger') {
+                	shareWeixin(share);
+                } else if (ua.match(/WeiBo/i) == 'weibo') {
+                	shareWeibo(share);
+                }
             }else{
                 console.log("错误"+xhr.status)
             }

+ 4 - 2
minigame/src/com/hssx/constant/Constant.java

@@ -7,8 +7,10 @@ package com.hssx.constant;
  * Version: 1.0
  */
 public class Constant {
-    public static final String MICROBLOG_APPKEY = "2141531565";//微博的appkey
-    public static final String MICROBLOG_APPSECRET = "f39462b939a56ce6d846bf83e04c20b5";//微博的accesstoken
+//    public static final String MICROBLOG_APPKEY = "2141531565";//微博的appkey
+//    public static final String MICROBLOG_APPSECRET = "f39462b939a56ce6d846bf83e04c20b5";//微博的accesstoken
+    public static final String MICROBLOG_APPKEY = "3741162137";//微博的appkey
+    public static final String MICROBLOG_APPSECRET = "a1b248c612b5f165b3402ee3861a5739";//微博的accesstoken
     public static final String WECHAT_APPID = "wx749c84daac654e1e";//微信的appid
     public static final String WECHAT_APPSECRET = "aacbd046ec1c790836f4f684c96fe585";//微信的appsecret
     public static final String CALLBACKURL = "https://wx.ttkuaiban.com/minigame/index.html";//微博返回code的回调地址

+ 2 - 1
minigame/src/com/hssx/controller/UserController.java

@@ -278,11 +278,12 @@ public class UserController {
 		// 随机数
 		String nonce_str = Sha1Util.getNonceStr();
 		String timestamp = Sha1Util.getTimeStamp();
+//		long timestamp = System.currentTimeMillis();
 		// 对以下字段进行签名
 		SortedMap<String, String> packageParams = new TreeMap<String, String>();
 		packageParams.put("jsapi_ticket", jsapiTicket);
 		packageParams.put("noncestr", nonce_str);
-		packageParams.put("timestamp", ""+timestamp);
+		packageParams.put("timestamp", timestamp);
 		packageParams.put("url", url);
 		String sign = Sha1Util.createSHA1Sign(packageParams);
 		packageParams.put("sign", sign);