{"size": 1794, "ext": "js", "max_stars_repo_path": "client/src/socialmedia/weixin.js", "max_stars_repo_name": "yunling2003/BlogNx", "max_stars_repo_stars_event_min_datetime": "2018-02-27T13:51:55.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-19T12:36:48.000Z", "max_issues_repo_path": "client/src/socialmedia/weixin.js", "max_issues_repo_name": "yunling2003/BlogNx", "max_issues_repo_issues_event_min_datetime": "2020-07-16T08:18:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T06:08:34.000Z", "max_forks_repo_path": "client/src/socialmedia/weixin.js", "max_forks_repo_name": "yunling2003/BlogNx", "max_forks_repo_forks_event_min_datetime": "2018-02-27T13:51:57.000Z", "max_forks_repo_forks_event_max_datetime": "2018-02-27T13:51:57.000Z"}
{"max_stars_count": 2, "max_issues_count": 4, "max_forks_count": 1, "avg_line_length": 35.1764705882, "max_line_length": 100, "alphanum_fraction": 0.4905239688}
import * as API from '../api'

export async function prepareWeixinShare(shareObj) {
    var retObj = await API.getWeixinSignature(shareObj.url)

    if(retObj.data && retObj.data.share) {
        wx.config({
            debug: false, 
            appId: retObj.data.share.appId, 
            timestamp: retObj.data.share.timestamp, 
            nonceStr: retObj.data.share.nonceStr, 
            signature: retObj.data.share.signature,
            jsApiList: [
                'updateAppMessageShareData',
                'updateTimelineShareData'
            ] 
        })
    
        wx.ready(function() {       
            wx.updateAppMessageShareData({ 
                title: shareObj.title,
                desc: shareObj.desc,
                link: shareObj.url,
                imgUrl: 'https://www.blognx.com/favicon.ico',
                success: function () {
                    if(shareObj.successCallback && typeof shareObj.successCallback === 'function') {
                        shareObj.successCallback()
                    }
                }
            })
            wx.updateTimelineShareData({ 
                title: shareObj.title,
                desc: shareObj.desc,
                link: shareObj.url,
                imgUrl: 'https://www.blognx.com/favicon.ico',
                success: function () {
                    if(shareObj.successCallback && typeof shareObj.successCallback === 'function') {
                        shareObj.successCallback()
                    }
                }
            })
        })
    
        wx.error(function (res) {
            console.log(res.errMsg)
            if(shareObj.errorCallback && typeof shareObj.errorCallback === 'function') {
                shareObj.errorCallback()
            }
        })
    }    
}