index.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import Taro from '@tarojs/taro'
  2. import { stringify, S4 } from '@/utils'
  3. import useHotLaunch from '@/hooks/useHotLaunch'
  4. import { RECOMMEND_PAGESOURCE, USER_SHARE_PAGESOURCE, CATEGORY_PAGESOURCE, DETAIL_PAGESOURCE, DETAIL_RECOMMEND } from '@/const'
  5. import { shareReport, weixinFriend, shareClickReport } from '@/logger'
  6. import { APP_ID, APP_TYPE, VERSION_CODE } from '@/config'
  7. export function sharePageAppMessage({ video, activeIndex, router, shareRes }) {
  8. useHotLaunch.valid = false
  9. const { path, params } = router
  10. const launchOption = Taro.$global.get('launchOption')
  11. const { target } = shareRes || {}
  12. const { dataset } = target || {}
  13. let query = shareQuary({
  14. path,
  15. video,
  16. pageSource: USER_SHARE_PAGESOURCE,
  17. recommendPageType: RECOMMEND_PAGESOURCE,
  18. parentRootPageSource: CATEGORY_PAGESOURCE,
  19. rootPageSource: params.rootPageSource,
  20. shareDepth: params.shareDepth,
  21. rootPageTimestamp: params.rootPageTimestamp,
  22. rootShareId: params.rootShareId,
  23. rootMid: params.rootMid,
  24. rootLaunchShareId: params.rootLaunchShareId,
  25. parentEventIds: params.eventIds,
  26. actionPosition: activeIndex,
  27. scene: launchOption.scene,
  28. shareButtonType: dataset?.buttonType || 0,
  29. prePageSource: '',
  30. })
  31. shareReport(query)
  32. weixinFriend(query)
  33. const detailPath = `/pages/share/share?${stringify(query)}`
  34. return {
  35. title: video.title || '好友分享给你一个视频,点击查看~',
  36. imageUrl: video.shareImgPath,
  37. path: `/pages/category/index?redirect=${encodeURIComponent(detailPath)}`
  38. }
  39. }
  40. export function shareVideoToWechat(params) {
  41. let query = shareQuary(params)
  42. const detailPath = `/pages/share/share?${stringify(query)}`
  43. return {
  44. path: `/pages/category/index?redirect=${encodeURIComponent(detailPath)}`
  45. }
  46. }
  47. function shareQuary(params){
  48. const { video } = params
  49. const mid = Taro.$global.get('mid')
  50. const shareId = mid + '-' + S4() + new Date().getTime()
  51. // TODO: 处理 pagesource
  52. let pageSource = video.pageSource
  53. const userInfo = Taro.$global.get('userInfo') || {}
  54. const query = {
  55. mid: mid,
  56. rootMid: params.rootMid || mid,
  57. shareId,
  58. pageSource,
  59. rootPageSource: params.rootPageSource || pageSource,
  60. flowPool: video.flowPool || '',
  61. launchscene: params.scene,
  62. su: userInfo.uid,
  63. recomTraceId: video.recomTraceId || '',
  64. rootPageTimestamp: params.rootPageTimestamp || new Date().getTime(),
  65. rootShareId: params.rootShareId || shareId,
  66. shareDepth: +params.shareDepth + 1 || 0,
  67. recommendSource: video.recommendSource,
  68. recommendLogVO: video.recommendLogVO || '{}',
  69. shareImageId: video.shareImgId,
  70. shareTitleId: video.titleId,
  71. shareButtonType: params.shareButtonType, // 按钮类型
  72. ...videoPlayParams(video)
  73. }
  74. return query
  75. }
  76. function videoPlayParams(video) {
  77. const {
  78. id, title, shareImgPath, videoPath,
  79. } = video
  80. return {
  81. title: encodeURIComponent(title || ''),
  82. videoPath: encodeURIComponent(videoPath),
  83. id,
  84. shareImgPath: encodeURIComponent(shareImgPath)
  85. }
  86. }
  87. export function shareTimeline({ video, messageActionType = 'videoShareH5', rootPageSource = null }) {
  88. const userInfo = Taro.$global.get('userInfo') || {}
  89. const systemInfo = Taro.$global.get('systemInfo') || {}
  90. const mid = Taro.$global.get('mid')
  91. let { flowPool = '', pageSource, id = 0, isRecommendShare = false } = video
  92. let session_from = {
  93. platform: systemInfo.system,
  94. appType: APP_TYPE,
  95. token: userInfo ? userInfo.accessToken : '',
  96. versionCode: VERSION_CODE,
  97. pageSource,
  98. machineCode: mid,
  99. rootPageSource: rootPageSource || pageSource,
  100. videoId: id,
  101. flowPool: flowPool.replace(/#/g, '_'),
  102. messageActionType,
  103. isRecommendShare,
  104. h5ShareIconClickTimeType: '0',
  105. }
  106. // let fomr = {
  107. // "h5ShareIconClickTimeType": "0",
  108. // "kitPosition": "",
  109. // "kitType": "",
  110. // "kitId": "",
  111. // "entranceType": "weapp_shareH5Button",
  112. // "xcxAbinfo": "eyJhYl90ZXN0MDAxIjp7ImciOiJhYjkiLCJpZCI6IjIyMywzNDEifSwiYWJfdGVzdDAwMiI6eyJnIjoiYWI5IiwiaWQiOiIzODYsNTA3LDU1NiJ9LCJhYl90ZXN0MDAzIjp7ImciOiJhYjgiLCJpZCI6IjQ5OSw1NzIifSwiYWJfdGVzdDAwNCI6eyJnIjoiYWI5IiwiaWQiOiIyMTEsMTI2In0sImFiX3Rlc3QwMDUiOnsiZyI6ImFiMTYiLCJpZCI6IiJ9LCJhYl90ZXN0MDA2Ijp7ImciOiJhYjE5IiwiaWQiOiIyNTMsMzEwLDMxNCwzMTEsMzIxLDM1OSwzNTYsMzcxLDMzMSw0MzQsNTExLDUxMiw1MTMsNTgyIn0sImFiX3Rlc3QwMDciOnsiZyI6ImFiMTAwIiwiaWQiOiIifX01"
  113. // }
  114. let obj = shareQuary({ video })
  115. const detailPath = `/pages/share/share?${stringify(obj)}`
  116. var msgPath = detailPath.replace(/%23/g, '_')
  117. return {
  118. session_from: JSON.stringify(session_from),
  119. send_msg_title: video.shareTitle,
  120. send_msg_img: 'https://weapppiccdn.yishihui.com/wxicon/wxOther/image/contact-share-h5-background-image.png',
  121. send_msg_path: '/'.concat(msgPath)
  122. }
  123. }
  124. // 分享回流上报
  125. export function returnedCrowdClickReport(params) {
  126. shareClickReport({
  127. shareId: params.shareId,
  128. clickObjectId: params.id || 0,
  129. pageSource: params.pageSource,
  130. rootPageSource: params.rootPageSource,
  131. shareButtonType: params.shareButtonType,
  132. shareDepth: params.shareDepth || 1,
  133. rootLaunchShareId: params.rootLaunchShareId || '',
  134. rootShareId: params.rootShareId || '',
  135. shareTitle: params.title,
  136. shareImageUrl: params.shareImgPath,
  137. shareTitleId: params.shareTitleId,
  138. shareImageId: params.shareImageId,
  139. parentShareId: params.parentShareId,
  140. extJson: JSON.stringify({
  141. parentRootPageSource: params.parentRootPageSource || params.rootPageSource,
  142. })
  143. })
  144. }