先上插件: https://github.com/iVanPan/Cordova_QQ/blob/master/README_ZH.md
安装:cordova plugin add cordova-plugin-qqsdk –variable
QQ_APP_ID=YOUR_QQ_APPID 腾讯开放平台:http://open.qq.com/ 注册你的应用你懂得不多说顺便提一下微博的插件:
https://github.com/iVanPan/cordova_weibo/blob/master/README_ZH.md
因为这个项目没用这个插件,所以就不贴了
/*点击分享按钮*/
$scope.p_share = function (title, desc, url, thumb) {
var hideSheet = $ionicActionSheet.show({
titleText: '分享到',
// destructiveText: 'Delete',
buttons: [
{text: "<div><div class='yuan-style kongjian'><i class='icon icon-qzone ion-share-another'></i></div> <div class='text-share-another'>QQ空间</div></div>"},
{text: "<div><div class='yuan-style weixin'><i class='icon icon-qq ion-share-another'></i></div> <div class='text-share-another'>QQ好友</div></div>"},
{text: "<div><div class='yuan-style pengyouquan'><i class='icon icon-pengyouquan ion-share-another'></i></div> <div class='text-share-another'>朋友圈</div></div>"},
{text: "<div><div class='yuan-style weibo'><i class='icon icon-weixin ion-share-another'></i></div> <div class='text-share-another'>微信好友</div></div>"},
{text: "<div><div class='yuan-style erweima'><i class='icon icon-erweima ion-share-another'></i></div> <div class='text-share-another'>二维码</div></div>"}
],
buttonClicked: function (index) {
/*当为0的时候执行buttons里第一个text的点击事件当为1的时候执行第二个,以此类推*/
MJC.myNotice(" <div style='text-align: center'><ion-spinner icon='ios' style='height: 60px; width: 60px;;'></ion-spinner> </div> ", 120000);
if (index == 0)//分享到QQ空间
{
//$scope.showloading = true;
var url;
if ($scope.check_load()) {
url = "http://mzhcar:9001/appWeb/prodetail.html?uid=" + Storage.load('user')[0]['Users_Id'] + "&pid=" + $scope.ProductDetail[0].Pro_Id;
}
else {
url = "http://mzhcar:9001/appWeb/prodetail.html?uid=0&pid=" + $scope.ProductDetail[0].Pro_Id;
}
var title = $scope.ProductDetail[0].Pro_Name;
var description = "茗家春绿茶(" + $scope.ProductDetail[0].tag + ")" + $scope.ProductDetail[0].Pro_Name + $scope.ProductDetail[0].Pro_DengJi;
var img =
[ENV.imgUrl + $scope.advert[0].image,
ENV.imgUrl + $scope.advert[1].image,
ENV.imgUrl + $scope.advert[2].image,
ENV.imgUrl + $scope.advert[3].image
];
YCQQ.checkClientInstalled(function () {
var args = {};
args.url = url;
args.title = title;
args.description = description;
args.imageUrl = img;
YCQQ.shareToQzone(function () {
MJC.myNotice("分享成功 ");
MJC.myNoticeClose();
}, function (failReason) {
MJC.myNotice("取消分享 ");
MJC.myNoticeClose();
}, args);
}, function () {
// 如果安装的QQ客户端版本太低,不支持SSO登录也会返回没有安装客户端的错误
MJC.myNotice("QQ客户端版本太低 ");
MJC.myNoticeClose();
});
}
if (index == 1)//分享到QQ好友
{
var url;
if ($scope.check_load()) {
url = "http://mzhcar:9001/appWeb/prodetail.html?uid=" + Storage.load('user')[0]['Users_Id'] + "&pid=" + $scope.ProductDetail[0].Pro_Id;
}
else {
url = "http://mzhcar:9001/appWeb/prodetail.html?uid=0&pid=" + $scope.ProductDetail[0].Pro_Id;
}
var title = $scope.ProductDetail[0].Pro_Name;
var description = "茗家春绿茶(" + $scope.ProductDetail[0].tag + ")" + $scope.ProductDetail[0].Pro_Name + $scope.ProductDetail[0].Pro_DengJi;
var imageUrl = ENV.imgUrl + $scope.advert[0].image;
var args = {};
args.url = url;
args.title = title;
args.description = description;
args.imageUrl = imageUrl;
args.appName = "茗家春茶";
//console.info(args);
//console.info($scope.ProductDetail);
YCQQ.checkClientInstalled(function () {
YCQQ.shareToQQ(function () {
//console.log("share success");
MJC.myNotice("分享成功 ");
MJC.myNoticeClose();
}, function (failReason) {
//console.log(failReason);
MJC.myNotice("取消分享 ");
MJC.myNoticeClose();
}, args);
}, function () {
// 如果安装的QQ客户端版本太低,不支持SSO登录也会返回没有安装客户端的错误
MJC.myNotice("QQ客户端版本太低 ");
MJC.myNoticeClose();
});
}
if (index == 2 || index == 3)//分享到微信朋友圈(2)
{
var scene;
if (index == 2) {
scene = Wechat.Scene.TIMELINE;//朋友圈
}
else {
scene = Wechat.Scene.SESSION; // session 好友
}
Wechat.isInstalled(function (installed) {
// alert("Wechat installed: " + (installed ? "Yes" : "No"));
if (installed == 1) {
var webpageUrl;
if ($scope.check_load()) {
webpageUrl = "http://mzhcar:9001/appWeb/prodetail.html?uid=" + Storage.load('user')[0]['Users_Id'] + "&pid=" + $scope.ProductDetail[0].Pro_Id;
}
else {
webpageUrl = "http://mzhcar:9001/appWeb/prodetail.html?uid=0&pid=" + $scope.ProductDetail[0].Pro_Id;
}
var title = $scope.ProductDetail[0].Pro_Name;
var description = "茗家春绿茶(" + $scope.ProductDetail[0].tag + ")" + $scope.ProductDetail[0].Pro_Name + $scope.ProductDetail[0].Pro_DengJi;
var thumb = ENV.imgUrl + $scope.advert[0].image;
Wechat.share({
message: {
title: title,
description: description,
thumb: thumb,
// mediaTagName: "TEST-TAG-001",
// messageExt: "这是第三方带的测试字段",
// messageAction: "<action>dotalist</action>",
//media: "YOUR_MEDIA_OBJECT_HERE"
media: {
type: Wechat.Type.LINK,
webpageUrl: webpageUrl//"www.baidu.com"
}
},
scene: scene //Wechat.Scene.TIMELINE // share to Timeline
}, function () {
//alert("Success");
MJC.myNotice("分享成功 ");
MJC.myNoticeClose();
}, function (reason) {
//alert("Failed: " + reason);
MJC.myNotice("取消分享 ");
MJC.myNoticeClose();
});
}
else {
MJC.myNotice("Wechat installed: " + (installed ? "Yes" : "No"));
MJC.myNoticeClose();
}
}
, function (reason) {
MJC.myNotice(reason);
MJC.myNoticeClose();
});
}
if (index == 4) {
YCQQ.checkClientInstalled(function () {
console.log('client is installed');
MJC.myNotice("installed");
MJC.myNoticeClose();
}, function () {
// 如果安装的QQ客户端版本太低,不支持SSO登录也会返回没有安装客户端的错误
console.log('client is not installed');
MJC.myNotice("client is not installed");
MJC.myNoticeClose();
});
}
},
cancelText: "取消",
cancel: function () {
//console.log('执行了取消操作');
MJC.myNoticeClose();
return true;
}
});
}