123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import Taro from '@tarojs/taro'
- import { stringify, S4 } from '@/utils'
- import useHotLaunch from '@/hooks/useHotLaunch'
- import { RECOMMEND_PAGESOURCE, USER_SHARE_PAGESOURCE, CATEGORY_PAGESOURCE, DETAIL_PAGESOURCE, DETAIL_RECOMMEND } from '@/const'
- import { shareReport, weixinFriend, shareClickReport } from '@/logger'
- import { APP_ID, APP_TYPE, VERSION_CODE } from '@/config'
- export function sharePageAppMessage({ video, activeIndex, router, shareRes }) {
- useHotLaunch.valid = false
- const { path, params } = router
- const launchOption = Taro.$global.get('launchOption')
- const { target } = shareRes || {}
- const { dataset } = target || {}
- let query = shareQuary({
- path,
- video,
- pageSource: USER_SHARE_PAGESOURCE,
- recommendPageType: RECOMMEND_PAGESOURCE,
- parentRootPageSource: CATEGORY_PAGESOURCE,
- rootPageSource: params.rootPageSource,
- shareDepth: params.shareDepth,
- rootPageTimestamp: params.rootPageTimestamp,
- rootShareId: params.rootShareId,
- rootMid: params.rootMid,
- rootLaunchShareId: params.rootLaunchShareId,
- parentEventIds: params.eventIds,
- actionPosition: activeIndex,
- scene: launchOption.scene,
- shareButtonType: dataset?.buttonType || 0,
- prePageSource: '',
- })
- shareReport(query)
- weixinFriend(query)
- const detailPath = `/pages/share/share?${stringify(query)}`
- return {
- title: video.title || '好友分享给你一个视频,点击查看~',
- imageUrl: video.shareImgPath,
- path: `/pages/category/index?redirect=${encodeURIComponent(detailPath)}`
- }
- }
- export function shareVideoToWechat(params) {
- let query = shareQuary(params)
- const detailPath = `/pages/share/share?${stringify(query)}`
- return {
- path: `/pages/category/index?redirect=${encodeURIComponent(detailPath)}`
- }
- }
- function shareQuary(params){
- const { video } = params
- const mid = Taro.$global.get('mid')
- const shareId = mid + '-' + S4() + new Date().getTime()
- // TODO: 处理 pagesource
- let pageSource = video.pageSource
- const userInfo = Taro.$global.get('userInfo') || {}
- const query = {
- mid: mid,
- rootMid: params.rootMid || mid,
- shareId,
- pageSource,
- rootPageSource: params.rootPageSource || pageSource,
- flowPool: video.flowPool || '',
- launchscene: params.scene,
- su: userInfo.uid,
- recomTraceId: video.recomTraceId || '',
- rootPageTimestamp: params.rootPageTimestamp || new Date().getTime(),
- rootShareId: params.rootShareId || shareId,
- shareDepth: +params.shareDepth + 1 || 0,
- recommendSource: video.recommendSource,
- recommendLogVO: video.recommendLogVO || '{}',
- shareImageId: video.shareImgId,
- shareTitleId: video.titleId,
- shareButtonType: params.shareButtonType, // 按钮类型
- ...videoPlayParams(video)
- }
- return query
- }
- function videoPlayParams(video) {
- const {
- id, title, shareImgPath, videoPath,
- } = video
- return {
- title: encodeURIComponent(title || ''),
- videoPath: encodeURIComponent(videoPath),
- id,
- shareImgPath: encodeURIComponent(shareImgPath)
- }
- }
- export function shareTimeline({ video, messageActionType = 'videoShareH5', rootPageSource = null }) {
- const userInfo = Taro.$global.get('userInfo') || {}
- const systemInfo = Taro.$global.get('systemInfo') || {}
- const mid = Taro.$global.get('mid')
- let { flowPool = '', pageSource, id = 0, isRecommendShare = false } = video
- let session_from = {
- platform: systemInfo.system,
- appType: APP_TYPE,
- token: userInfo ? userInfo.accessToken : '',
- versionCode: VERSION_CODE,
- pageSource,
- machineCode: mid,
- rootPageSource: rootPageSource || pageSource,
- videoId: id,
- flowPool: flowPool.replace(/#/g, '_'),
- messageActionType,
- isRecommendShare,
- h5ShareIconClickTimeType: '0',
- }
- // let fomr = {
- // "h5ShareIconClickTimeType": "0",
- // "kitPosition": "",
- // "kitType": "",
- // "kitId": "",
- // "entranceType": "weapp_shareH5Button",
- // "xcxAbinfo": "eyJhYl90ZXN0MDAxIjp7ImciOiJhYjkiLCJpZCI6IjIyMywzNDEifSwiYWJfdGVzdDAwMiI6eyJnIjoiYWI5IiwiaWQiOiIzODYsNTA3LDU1NiJ9LCJhYl90ZXN0MDAzIjp7ImciOiJhYjgiLCJpZCI6IjQ5OSw1NzIifSwiYWJfdGVzdDAwNCI6eyJnIjoiYWI5IiwiaWQiOiIyMTEsMTI2In0sImFiX3Rlc3QwMDUiOnsiZyI6ImFiMTYiLCJpZCI6IiJ9LCJhYl90ZXN0MDA2Ijp7ImciOiJhYjE5IiwiaWQiOiIyNTMsMzEwLDMxNCwzMTEsMzIxLDM1OSwzNTYsMzcxLDMzMSw0MzQsNTExLDUxMiw1MTMsNTgyIn0sImFiX3Rlc3QwMDciOnsiZyI6ImFiMTAwIiwiaWQiOiIifX01"
- // }
- let obj = shareQuary({ video })
- const detailPath = `/pages/share/share?${stringify(obj)}`
- var msgPath = detailPath.replace(/%23/g, '_')
- return {
- session_from: JSON.stringify(session_from),
- send_msg_title: video.shareTitle,
- send_msg_img: 'https://weapppiccdn.yishihui.com/wxicon/wxOther/image/contact-share-h5-background-image.png',
- send_msg_path: '/'.concat(msgPath)
- }
- }
- // 分享回流上报
- export function returnedCrowdClickReport(params) {
- shareClickReport({
- shareId: params.shareId,
- clickObjectId: params.id || 0,
- pageSource: params.pageSource,
- rootPageSource: params.rootPageSource,
- shareButtonType: params.shareButtonType,
- shareDepth: params.shareDepth || 1,
- rootLaunchShareId: params.rootLaunchShareId || '',
- rootShareId: params.rootShareId || '',
- shareTitle: params.title,
- shareImageUrl: params.shareImgPath,
- shareTitleId: params.shareTitleId,
- shareImageId: params.shareImageId,
- parentShareId: params.parentShareId,
- extJson: JSON.stringify({
- parentRootPageSource: params.parentRootPageSource || params.rootPageSource,
- })
- })
- }
|