标签:target success ima ddl lin tencent hone comm png
QQ登录、分享怎么做?相信APICloud可以让你开发变得很简单。这里分享一个demo供大家参考。
1.使用模块,先打开它的开发文档http://www.apicloud.com/mod_detail/37360
添加模块至APIcloud项目
2. 编译自定义loader
3. 在腾讯开放平台管理中心创建应用,提交审核,拿到appkey和appId
4. 在项目代码中找到config.xml
添加代码
<font face="微软雅黑" size="3"><feature name="QQPlus">
<param name="urlScheme" value="" />
<param name="apiKey" value="" />
</feature></font>
复制代码
5.拼接urlScheme和appkey
urlScheme =》tencent加上你的appId
Appkey =》appkey
填入第四步的位置
6. 可以在他的代码里边找相应的方法代码......
7.备注:腾讯开放平台项目未审核通过,有些功能会出问题,分享操作先登录,登录先验证安装。
附图:
代码:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>QQ</title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<link rel="stylesheet" type="text/css" href="../css/aui.css" />
</head>
<body>
<div class="aui-content-padded">
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(1)">检测安装</div></p>
<p><div class="aui-btn aui-btn-info aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(2)">QQ登录</div></p>
<p><div class="aui-btn aui-btn-success aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(3)">获取用户信息</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(4)">分享文本</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(5)">分享图片</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(6)">分享新闻</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(7)">分享音乐</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(8)">分享视频</div></p>
<p><div class="aui-btn aui-btn-primary aui-btn-block aui-btn-sm aui-margin-b-15" onclick="fnEvent(9)">分享说说</div></p>
</div>
</body>
< type="text/java" src="..//api.js"></>
< type="text/java">
apiready = function() {
qq = api.require(‘QQPlus‘);
};
function fnEvent(tag) {
switch (tag) {
case 1:
fnInstalled();
break;
case 2:
fnLogin();
break;
case 3:
fnGetUserInfo();
break;
case 4:
fnShareText();
break;
case 5:
fnShareImage();
break;
case 6:
fnShareNews();
break;
case 7:
fnShareMusic();
break;
case 8:
fnShareVideo();
break;
case 9:
fnShareMood();
break;
default:
break;
};
}
/**
* 检测安装
*/
function fnInstalled() {
qq.installed(function(ret, err) {
if (ret.status) {
api.toast({msg: "已安装QQ"});
} else {
api.toast({msg: "没安装QQ"});
};
});
};
/**
* QQ登录
*/
function fnLogin() {
qq.installed(function(ret, err) {
if (ret.status) {
qq.login(function(ret, err) {
if (ret.status) {
console.log("登录成功");
console.log(JSON.stringify(ret));
} else {
console.log(JSON.stringify(err));
}
});
};
});
};
/**
* 获取用户信息
*/
function fnGetUserInfo() {
qq.getUserInfo(function(ret, err) {
if (ret.status) {
console.log(JSON.stringify(ret.info));
info = ret.info.replace(/[\\]/g,‘‘);
console.log(info);
} else {
console.log(JSON.stringify(err));
}
});
};
/**
* 分享文本
*/
function fnShareText() {
api.prompt({
title:"输入要分享的文本",
buttons: [‘确定‘,"取消"]
}, function(ret, err) {
var index = ret.buttonIndex;
var text = ret.text;
console.log(index);
if(index != 1 ){
api.toast({msg:"用户取消!"});
}else if(index == 1 && $api.trimAll(text) == ‘‘){
api.toast({msg:"请输入分享内容"});
}else if(index == 1 && $api.trimAll(text) != ‘‘){
_fnShareText($api.trimAll(text));
}
});
function _fnShareText(text){
qq.shareText({
text: text
}, function(ret, err) {
if (ret.status) {
console.log("分享文本成功!");
console.log(JSON.stringify(ret));
} else {
console.log(JSON.stringify(err));
}
});
}
};
/**
* 分享图片
*/
function fnShareImage() {
api.confirm({
title: ‘选项‘,
msg: ‘请选择分享至‘,
buttons: [ ‘QQ好友‘,‘QQ空间‘]
}, function(ret, err) {
_fnShareImage(ret.buttonIndex);
});
function _fnShareImage(i) {
var type = [‘QZone‘, ‘QFriend‘];
qq.shareImage({
type: type[i],
imgPath: ‘widget://launch/launch1080x1920.png‘
}, function(ret, err) {
if (ret.status) {
console.log("分享图片成功!");
console.log(JSON.stringify(ret));
} else {
console.log(JSON.stringify(err));
}
});
};
};
/**
* 分享新闻
*/
function fnShareNews() {
api.confirm({
title: ‘选项‘,
msg: ‘请选择分享至‘,
buttons: [ ‘QQ好友‘,‘QQ空间‘]
}, function(ret, err) {
_fnShareNews(ret.buttonIndex);
});
function _fnShareNews(i) {
var type = [‘QZone‘, ‘QFriend‘];
qq.shareNews({
type: type[i],
url: ‘https://news.qq.com/a/20171108/029944.htm‘,
title: ‘携程:被虐儿童为18至24个月幼儿 亲子园明日停业‘,
deion: ‘携程:被虐儿童为18至24个月幼儿 亲子园明日停业‘,
imgUrl: ‘http://inews.gtimg.com/newsapp_bt/0/2264720095/641‘
}, function(ret, err) {
if (ret.status) {
console.log("分享新闻成功!");
console.log(JSON.stringify(ret));
} else {
console.log(JSON.stringify(err));
}
});
};
};
/**
* 分享音乐
*/
function fnShareMusic() {
api.confirm({
title: ‘选项‘,
msg: ‘请选择分享至‘,
buttons: [ ‘QQ好友‘,‘QQ空间‘]
}, function(ret, err) {
_fnShareMusic(ret.buttonIndex);
});
function _fnShareMusic(i) {
var type = [‘QZone‘, ‘QFriend‘];
qq.shareMusic({
type: type[i],
audioUrl: ‘http://7xq864.com1.z0.glb.clouddn.com/apicloud/591bde468d4e44b21cc225b7b6e1129a.mp3‘,
targetUrl: ‘http://douban.fm/?start=8508g3c27g-3&cid=-3‘,
title: ‘桔子香水‘,
deion: ‘任贤齐‘,
imgUrl: ‘http://community.apicloud.com/bbs/uc_server/avatar.php?uid=441392&size=middle‘
}, function(ret, err) {
if (ret.status) {
console.log("分享音乐成功!");
} else {
console.log(JSON.stringify(err));
}
});
}
};
/**
* 分享视频
*/
function fnShareVideo() {
qq.shareVideo({
videoUrl: ‘widget://image/APICloud.mp4‘
}, function(ret, err) {
if (ret.status) {
console.log("分享视频成功!");
} else {
console.log(JSON.stringify(err));
}
});
}
/**
* 分享说说
*/
function fnShareMood() {
qq.shareMood({
summary: ‘测试分享说说‘,
imgUrls: [‘widget://icon/icon150x150.png‘]
}, function(ret, err) {
if (ret.status) {
console.log("分享说说成功!");
} else {
console.log(JSON.stringify(err));
}
});
}
</>
</html>
更多信息请关注https://www.apicloud.com
APICloud可以让你开发变得很简单
标签:target success ima ddl lin tencent hone comm png
原文地址:http://www.cnblogs.com/apicloud/p/7880576.html