安装工具包 npm i xctc-utils
项目中引入 import utils from "xctc-utils"
在项目启动文件中调用启动方法,如在react项目的APP.tsx文件中初始化使用
微信分享等相关涉及加密的地方,通过 crypto-js 进行加密
微信跳转授权及登录配置加载:weixinUrlCode
weixinUrlCode方法通过检测地址栏是否带有 code 参数进行微信授权跳转,授权成功后截取 code 参数,并进行本地临时存储。
const config = {
appId:AppConfig.appId,
http:serve.deft.wxLogin,
scope:"",
codeKey:"",
stateKey:"",
cryptoiv:"",
cryptokey:"",
}
微信登录时,config中的http方法参数格式,前端传输、后端接收数据为:
let obj = {
"app_id": appId ,
"js_code":code
}
utils.weixinUrlCode(config)
微信分享配置接口加载:weixinShareConfig,在APP.tsx文件中初始化使用
const shareConfig = {
appId:AppConfig.appId,
http:serve.deft.weixinShareConfig,
cb:()=>{
},
jsApiList?:string[],
}
微信分享配置接口(http)参数格式为:param,其中url自动截取,appId为shareConfig配置参数
let param = {
url:url,
appId:config.appId,
}
utils.weixinShareConfig(shareConfig)
各页面中微信分享调用:
interface ShareOptions = {
title?:string,
desc?:string,
link: '',
imgUrl: '',
data?:any,
iv?:string,
key?:string,
}
如:
let shareConfig = {
title:"分享标题",
desc:"分享描述",
link:"https://www.xx.com",
imgUrl:"https://www.xx.com/image/logo.png",
iv:"",
key:"",
data:{
id:id,
path:"/service/employment-index"
}
}
utils.weixinShareInit(shareConfig)