/**
 * [OElove] (C)2010-2099 oelove.com Inc.biz
 * Email: service@phpcoo.com，phpcoo@qq.com
 * This is not a freeware, use is subject to license terms
 * $ LastTime 2020.02.17 Update by OE/CL $ 微信分享
*/
$(function(){
    
    function OEWxShare() {
        //分享参数
        this.share_title = '';
        this.share_des = '';
        this.share_img = '';
        this.share_url = '';
        //默认内容
        this.diy_title = '一个容易找到对象的婚恋平台';
        this.diy_des = '送你一个对象请查收！脱单利器，点击进入马上领取。';
        this.diy_siteurl = '';
        
        //getwx url 
        this.getwx_url = _ROOT_PATH+'index.php?m=wap&c=wxapi&a=share';
        
        this.wake();
    }
    
    OEWxShare.prototype = {
        
        //组合参数
        wake:function() {
            var _this = this;
            
            _this.share_title = $("#share_title").val();
            if (typeof(_this.share_title) == 'undefined') {
                _this.share_title = '';
            }
            _this.share_des = $("#share_des").val();
            if (typeof(_this.share_des) == 'undefined') {
                _this.share_des = '';
            }
            _this.share_img = $("#share_img").val();
            if (typeof(_this.share_img) == 'undefined') {
                _this.share_img = '';
            }
            _this.share_url = $("#share_url").val();
            if (typeof(_this.share_url) == 'undefined') {
                _this.share_url = '';
            }
            
            _this.diy_siteurl = $("#share_siteurl").val(); //网站地址
            if (typeof(_this.diy_siteurl) == 'undefined') {
                _this.diy_siteurl = '';
            }
            //处理没有标题和内容，使用默认的值
            if (_this.share_title == '') {
                _this.share_title = _this.diy_title;
                _this.share_des = _this.diy_des;
                _this.share_url = _this.diy_siteurl;
            }
            
            //生成分享参数
            var share_timeout = null;
            setTimeout(function(){
                share_timeout = _this.getWxJs();
                clearTimeout(share_timeout);
            }, 1000);
            
        },
        
        //获取微信参数
        getWxJs:function() {
            var _this = this;
            
            $.ajax({
                type: "POST",
                url: _this.getwx_url,
                cache: false,
                data: {
                    title:_this.share_title, desc:_this.share_des, 
                    imgurl:_this.share_img, httpurl:_this.share_url
                },
                dataType: "json",
                success: function($data) {
                    $json = eval($data);
                    $response = $json.response;
                    $result = $json.result;
                    if ($response == "1") { 
                        $("body").append($result); //载入wxapi js
                    }
                },
                error: function() {
                }
            });
        }
    }
    new OEWxShare();
});