1、打開app項目的manifest.json的文件,選擇模塊權限配置,將Share(分享)模塊添加至已選模塊中

2、選擇SDK配置,在plus.share·分享中,勾選□ 微信消息及朋友圈,配置好appid和appsecret值(appid/appsecret可以在微信開發者平台創建應用獲取)

3、項目JS文件中的微信支付代碼如下(基於angular開發):
$scope.inviteFrendShareFn = function() { //分享方法 if($scope.userLoginFlag){ shareHref() }else{ $state.go('sign'); } }; var shares = null; function plusReady() { updateSerivces(); if (plus.os.name == "Android") { //安卓系統處理 main = plus.android.runtimeMainActivity(); Intent = plus.android.importClass("android.content.Intent"); File = plus.android.importClass("java.io.File"); Uri = plus.android.importClass("android.net.Uri") } } if (window.plus) { plusReady() } else { document.addEventListener("plusready", plusReady, false) } function updateSerivces() { //獲取分享服務 plus.share.getServices(function(s) { shares = {}; for (var i in s) { var t = s[i]; shares[t.id] = t } }, function(e) { alert("獲取分享服務列表失敗:" + e.message) }) } function shareAction(sb, bh) { //分享方法 var int; //分享鏈接 $http.post(url + "/xxxx", {}).success(function(data) { console.log("/xxxx:"+JSON.stringify(data)); int = url + `/index.html#/shareView?userKey=${data.data.user_key}&invitePhone=${data.data.phone}`; console.log("shareUrl:"+int); $scope.wxshareUrl = int; if (!sb || !sb.s) { alert("無效的分享服務!"); return } var msg = { content: "這是分享內容", extra: { scene: sb.x } }; if (bh) { msg.href = int; msg.title = '這是分享標題'; msg.content = "這是分享內容"; msg.thumbs = ["這里放分享顯示的應用圖標鏈接"]; //http://xxx.xxx/logo.gif msg.pictures = ["這里放分享顯示的應用圖標鏈接"] //http://xxx.xxx/logo.gif } if (sb.s.authenticated) { shareMessage(msg, sb.s) } else { sb.s.authorize(function() { shareMessage(msg, sb.s) }, function(e) {}) } }) } function shareMessage(msg, s) { //分享回調 s.send(msg, function() { $ionicPopup.alert({ title: '提示', template: "分享到\"" + s.description + "\"成功! ", okText: '確定' }) }, function(e) { $ionicPopup.alert({ title: '提示', template: "分享到\"" + s.description + "\"失敗! ", okText: '確定' }) }) } function shareHref() { //分享按鈕 var shareBts = []; var ss = shares['weixin']; ss && ss.nativeClient && (shareBts.push({ title: '微信朋友圈', s: ss, x: 'WXSceneTimeline' }), shareBts.push({ title: '微信好友', s: ss, x: 'WXSceneSession' })); shareBts.length > 0 ? plus.nativeUI.actionSheet({ cancel: '取消', buttons: shareBts }, function(e) { e.index > 0 && shareAction(shareBts[e.index - 1], true) }) : plus.nativeUI.alert('當前環境無法支持分享鏈接操作!') }
ps:HTML5+參考文檔
