angular中微信分享问题
// 微信 JS SDK 分享
angular.module("pharmacyApp").factory("ShareService", ["$http", "$window","$timeout","$cookies",
function ($http, $window,$timeout,$cookies) {
// 封装请求参数
var config = {
method: 'get', // 方法类型
url: '/h5/jsApiParams/get', // 地址
params: { // 参数
url: $window.location.href,
groupId : $cookies.get("branchGroupId") || '',
branchId: $cookies.get("branchId") || '',
platform : "N"
},
headers: {"Content-Type": "text/json; charset=UTF-8"}, // 头部
cache: false, // 是否使用缓存
timeout: 30000 // 响应时长
};
var jsApiParams = function(title,desc,link,imgUrl){
imgUrl = (imgUrl && imgUrl != '') ? imgUrl : $window.location.protocol+'//'+$window.location.host+'/QWWAP_NG/common/img/icon_300.png';
$http(config).success(function(data){
var res = data.body;
if(data.result != 'OK'){ return; }
if (res.apiStatus === 0) {
var config = data.body,
shareData = { title: title, desc: desc, link: link, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('1');
}, cancel: function () { }},
shareData2 = { title: desc, desc: title, link: link, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('2');
}, cancel: function () { }},
shareData3 = { title: desc, desc: title, link: $window.location.href, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('3');
}, cancel: function () { }},
auth_list = ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone','onMenuShareWeibo','hideOptionMenu','showOptionMenu','hideMenuItems','showMenuItems','hideAllNonBaseMenuItem','showAllNonBaseMenuItem'];
wx.config({
debug: true,
appId: config.appId,
timestamp: config.timestamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: auth_list
});
wx.ready(function() {
wx.checkJsApi({ jsApiList:auth_list, error:function(res){ alert("您的微信客户端太低,请升级后再试!"); } });
wx.onMenuShareTimeline(shareData2);
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareQQ(shareData3);
wx.onMenuShareWeibo(shareData3);
});
}
});
};
//自定义分享
var wx_share = function (title,desc,link,imgUrl) {
jsApiParams(title,desc,link,imgUrl);
};
return {
wx_share: wx_share
};
}]);
红色标注:wx.config 设置后 wx.ready 方法有时候能正常执行,有时候不能执行,我通过用javascript正常写法, wx.ready每次都能执行,经过测试得出的结果,angular中调用 wx.config 后wx.ready不一定能执行,因为wx.config是异步方法,虽然angular对异步有相关处理方式,基于这种情况,不知道该怎么解决,跪谢!!!!!
angular.module("pharmacyApp").factory("ShareService", ["$http", "$window","$timeout","$cookies",
function ($http, $window,$timeout,$cookies) {
// 封装请求参数
var config = {
method: 'get', // 方法类型
url: '/h5/jsApiParams/get', // 地址
params: { // 参数
url: $window.location.href,
groupId : $cookies.get("branchGroupId") || '',
branchId: $cookies.get("branchId") || '',
platform : "N"
},
headers: {"Content-Type": "text/json; charset=UTF-8"}, // 头部
cache: false, // 是否使用缓存
timeout: 30000 // 响应时长
};
var jsApiParams = function(title,desc,link,imgUrl){
imgUrl = (imgUrl && imgUrl != '') ? imgUrl : $window.location.protocol+'//'+$window.location.host+'/QWWAP_NG/common/img/icon_300.png';
$http(config).success(function(data){
var res = data.body;
if(data.result != 'OK'){ return; }
if (res.apiStatus === 0) {
var config = data.body,
shareData = { title: title, desc: desc, link: link, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('1');
}, cancel: function () { }},
shareData2 = { title: desc, desc: title, link: link, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('2');
}, cancel: function () { }},
shareData3 = { title: desc, desc: title, link: $window.location.href, imgUrl: imgUrl, type: 'link', dataUrl: '', success: function () {
alert('3');
}, cancel: function () { }},
auth_list = ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone','onMenuShareWeibo','hideOptionMenu','showOptionMenu','hideMenuItems','showMenuItems','hideAllNonBaseMenuItem','showAllNonBaseMenuItem'];
wx.config({
debug: true,
appId: config.appId,
timestamp: config.timestamp,
nonceStr: config.nonceStr,
signature: config.signature,
jsApiList: auth_list
});
wx.ready(function() {
wx.checkJsApi({ jsApiList:auth_list, error:function(res){ alert("您的微信客户端太低,请升级后再试!"); } });
wx.onMenuShareTimeline(shareData2);
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareQQ(shareData3);
wx.onMenuShareWeibo(shareData3);
});
}
});
};
//自定义分享
var wx_share = function (title,desc,link,imgUrl) {
jsApiParams(title,desc,link,imgUrl);
};
return {
wx_share: wx_share
};
}]);
红色标注:wx.config 设置后 wx.ready 方法有时候能正常执行,有时候不能执行,我通过用javascript正常写法, wx.ready每次都能执行,经过测试得出的结果,angular中调用 wx.config 后wx.ready不一定能执行,因为wx.config是异步方法,虽然angular对异步有相关处理方式,基于这种情况,不知道该怎么解决,跪谢!!!!!
...全文
相关推荐
Amini 是一个 Angular 风格的微信小程序开发库.zip
Amini 是一个 Angular 风格的微信小程序开发库.zip
share-js:分享组件
share-js 这是一个touch端关于分享得组件包括微博分享得组件,包括基本的社交网站的分享 普通浏览器用share.js 微信浏览器用shareweixin.js.
微信页面的实现
微信
微信社群人脉系统社群空间站源码
微信社群人脉系统社群空间站源码
Angular2+如何去除url中的#号详解
主要给大家介绍了关于Angular 2+时如何去除url中#号的相关资料,文中先对#号去除的原因及方法进行详细的介绍和分析,然后通过示例代码给大家演示去除的方法,需要的朋友可以参考借鉴,下面随着小编来一起看看吧。


