import wx from 'jweixin-1.6.0';
import { getOfficialAccountSignature } from '@/request/admin/weChat';
type ParamInfo = {
url: string;
title: string;
desc: string;
imgUrl: string;
};
export function shareWechat(param: ParamInfo) {
const { url, title, desc, imgUrl } = param;
getOfficialAccountSignature({ url }).then((wechatRes) => {
const { appId, timestamp, nonceStr, signature } = wechatRes;
const imgUrlOSS = `${imgUrl}?x-oss-process=image/resize,m_fill,h_100,w_100`;
wx.config({
debug: false,
appId,
timestamp,
nonceStr,
signature,
jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData']
});
wx.ready(function () {
wx.updateAppMessageShareData({
title,
desc,
link: url,
imgUrl: imgUrlOSS
});
wx.updateTimelineShareData({
title,
link: url,
imgUrl: imgUrlOSS
});
});
});
}