|
本帖最后由 klayzhang 于 2016-3-9 11:33 编辑
在做分享之前需要在微信,qq,微博这几个开放平台注册账号并拿到相关的key,然后再插件使用的时候进行填写(一定要注意插件中参数必须正确,插件在native中的plugins已经有了)
//微信,分享到朋友圈
Model.prototype.weixinShareSessionClick = function(event){
var Utils = require("$UI/system/components/justep/common/utils");
var goodsRow = this.comp("goodsData").getFirstRow();
var title = goodsRow.val("name");
var intro = goodsRow.val("intro");
var picPath = util.getServerUrl(util.getFirstImage(goodsRow.val("picPaths")));// "http://ww1.sinaimg.cn/mw600/b4ece975tw1e33ep5rqfmj.jpg" (image max size 22kb)
if (!navigator.weixin) {
justep.Util.hint("请在手机上操作")
return;
}
var weixin = navigator.weixin;
weixin.share({
message : {
title : title,
description : "",
mediaTagName : "",
thumb : picPath,
media : {
type : weixin.Type.WEBPAGE,
webpageUrl :Utils.getShareUrl()
}
},
scene : weixin.Scene.TIMELINE //weixin.Scene.SESSION :分享到好友
}, function() {
justep.Util.hint("分享成功!")
}, function(reason) {
// alert("Failed: " + reason);
});
};
//qq分享到空间
Model.prototype.qqZoneClick = function(event){
if (!navigator.QQ) {
justep.Util.hint("请在手机上操作")
return;
}
var Utils = require("$UI/system/components/justep/common/utils");
var goodsRow = this.comp("goodsData").getFirstRow();
var title = goodsRow.val("name");
var intro = goodsRow.val("intro");
var picPath = util.getServerUrl(util.getFirstImage(goodsRow.val("picPaths")));
var args = {};
args.url = Utils.getShareUrl();
args.title = title;
args.description = "";
var imgs =[picPath];
args.imageUrl = imgs;
navigator.QQ.shareToQzone(function () {
justep.Util.hint("分享成功!")
}, function (failReason) {
}, args);
};
//分享好友,群...
Model.prototype.qqShareClick = function(event){
if (!navigator.QQ) {
justep.Util.hint("请在手机上操作")
return;
}
var Utils = require("$UI/system/components/justep/common/utils");
var goodsRow = this.comp("goodsData").getFirstRow();
var title = goodsRow.val("name");
var intro = goodsRow.val("intro");
var picPath = util.getServerUrl(util.getFirstImage(goodsRow.val("picPaths")));
var args = {};
args.url = Utils.getShareUrl();
args.title = title;
args.description = "";
args.imageUrl = picPath;
args.appName = ";
navigator.QQ.shareToQQ(function(){
justep.Util.hint("分享成功!")
},function(failReason){
console.log(failReason);
},args);
};
//分享到微博
Model.prototype.weiboShareClick = function(event){
if (!navigator.Weibo) {
justep.Util.hint("请在手机上操作")
return;
}
var Utils = require("$UI/system/components/justep/common/utils");
var goodsRow = this.comp("goodsData").getFirstRow();
var title = goodsRow.val("name");
var intro = goodsRow.val("intro");
var picPath = util.getServerUrl(util.getFirstImage(goodsRow.val("picPaths")));
var args = {};
args.url = Utils.getShareUrl();
args.title = title;
args.description = "";
args.imageUrl = picPath;//if you don't have imageUrl,for android http://"www.sinaimg.cn/blog/developer/wiki/LOGO_64x64.png will be the defualt one"
args.defaultText = "";
navigator.Weibo.shareToWeibo(function () {
justep.Util.hint("分享成功!")
}, function (failReason) {
//alert(failReason);
}, args);
};
以上就是几个简单的例子,微信分享时候一定要注意thumb参数的图片大小,还有就是各大开发平台的key
|
|