/*
 * 微信分享模块;
 * @author yhw;
 */
define(['http://res.wx.qq.com/open/js/jweixin-1.0.0.js'], function (wx) {
    var api = "http://api.weixin.37wan.com/js-sdk/index.php?a=get_sign_package";
    return function (setData) {
        var setData = setData || {};
        var _share = function (setData) {
            var desc = setData.desc || document.title, 	// 分享描述;
                purl = setData.picUrl, 					// 分享图标;
                title = setData.title,       			// 分享标题;
                slink = setData.url,          			// 分享链接;
                successA = setData.successA || function () {
                    }, // 分享给朋友：用户确认分享后执行的回调函数
                successT = setData.successT || function () {
                    }; // 分享朋友圈：用户确认分享后执行的回调函数
            // console.log(desc);
            wx.ready(function () {
                // 分享给朋友;
                var shareData = {
                        title: title,
                        desc: desc,
                        link: slink,
                        imgUrl: purl,
                        success: successA,
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    },
                // 朋友圈;
                    shareData1 = {
                        title: desc,
                        link: slink,
                        imgUrl: purl,
                        success: successT,
                        cancel: function () {
                            // 用户取消分享后执行的回调函数
                        }
                    };
                wx.onMenuShareAppMessage(shareData);
                wx.onMenuShareTimeline(shareData1); // 朋友圈;

            });
        };

        $.ajax({
            url: api,
            dataType: "jsonp",
            data: {
                url: location.href
            },
            success: function (res) {
                wx.config({
                    debug: false,
                    appId: res.list.appId,
                    timestamp: res.list.timestamp,
                    nonceStr: res.list.nonceStr,
                    signature: res.list.signature,
                    jsApiList: [
                        "onMenuShareTimeline",
                        "onMenuShareAppMessage",
                        "onMenuShareQQ",
                        "onMenuShareWeibo"
                    ]
                });
                _share(setData);
                return shareWx = _share; // 重写分享；
            }
        });
    }
});