Browse Source

更新 分享参数

wangzhihui 4 years ago
parent
commit
9b4642465c

+ 2 - 1
cloudfunctions/api/index.js

@@ -68,7 +68,8 @@ exports.main = async (event, context) => {
     let res = await got(url)
     let result = JSON.parse(res.body)
     ctx.body = {
-      ...result
+      ...result,
+      _openid
     }
 
     await next()

+ 7 - 4
miniprogram/pages/index/index.js

@@ -15,9 +15,13 @@ Page({
 
   },
   go() {
-    wx.navigateTo({
-      url: '/pages/takePhoto/takePhoto',
-    })
+    if (wx.getStorageSync('userId')) {
+      wx.navigateTo({
+        url: '/pages/takePhoto/takePhoto',
+      })
+    } else {
+      this.getOpenid()
+    }
   },
   async getOpenid() {
     let res = await cloudApi("getOpenId")
@@ -28,7 +32,6 @@ Page({
     let res1 = await postApi("/user/wx/login", {
       openId
     })
-    console.log(res1)
 
     if (res1.data.status == 0) {
       let data = {

+ 6 - 2
miniprogram/pages/share/share.js

@@ -4,9 +4,13 @@ Page({
     shareImageUrl: ''
   },
   onLoad: function (options) {
-    // 小程序解析带有多个等号的参数时,无法解析等号后面的参数,故=号互相替换%%%%%%
+    console.log(options)
+
+
+
+
     this.setData({
-      shareImageUrl: options.shareImageUrl.replace(/%%%%%%/g, "=")
+      shareImageUrl: (options.shareImageUrl.replace(/qwerdfb000mmmccc/g, '?')).replace(/mmmcccqwerdfb/g, '=')
     })
   }
 })

+ 2 - 1
miniprogram/pages/share/share.wxml

@@ -1 +1,2 @@
-<image mode="aspectFit" src="{{shareImageUrl}}" style="width: 100%;margin-top: 30%;"></image>
+<image mode="aspectFit" src="{{shareImageUrl}}" style="width: 100vw;margin-top: 30%;border:1px solid red"></image>
+{{shareImageUrl}}

+ 1 - 2
miniprogram/pages/takePhoto/success/success.js

@@ -10,11 +10,10 @@ Page({
   onShareAppMessage() {
     let shareImageUrl = wx.getStorageSync('shareImageUrl')
 
-
     return {
       title: '真实 实时 精准',
       // 小程序解析带有多个等号的参数时,无法解析等号后面的参数,故=号互相替换%%%%%%
-      path: `/pages/share/share?shareImageUrl=${shareImageUrl.replace(/=/g,'%%%%%%')}`,
+      path: `/pages/share/share?shareImageUrl=${(shareImageUrl.replace(/\?/g, 'qwerdfb000mmmccc')).replace(/=/g, 'mmmcccqwerdfb')}`,
       imageUrl: shareImageUrl
     }
   }

+ 1 - 1
miniprogram/pages/takePhoto/success/success.wxml

@@ -1,7 +1,7 @@
 <view style="width: 100%;">
   <image style="width: 300rpx;height: 300rpx;border-radius:50%;margin:0 auto;margin-top: 235rpx;display: block;" src="https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/green-circle-right-icon.jpg?sign=7fa6e412d07bfa0d5144ed2ed2716fff&t=1634542189"></image>
 </view>
-<view style="width: 100%;height: 48rpx;text-align:center;font-size: 34rpx;font-family: PingFangSC-Medium,PingFang SC;font-weight: 500;color: #0094FE;line-height: 48rpx;margin-top: 60rpx;">视频/图片上传成功
+<view style="width: 100%;height: 48rpx;text-align:center;font-size: 34rpx;font-family: PingFangSC-Medium,PingFang SC;font-weight: 500;color: #0094FE;line-height: 48rpx;margin-top: 60rpx;">图片上传成功
 </view>
 <view bindtap="go" style="margin:0 auto;margin-top:156rpx;width: 650rpx;height: 80rpx;background:#0094FE;border-radius: 4rpx;color: #fff;text-align: center;font-size: 34rpx;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;line-height: 80rpx;">继续拍照</view>
 <button open-type="share" bindtap="share" style="margin:0 auto;margin-top:40rpx;width: 650rpx;height: 80rpx;line-height:50rpx!important;border-radius: 4rpx;color: #0094FE;text-align: center;font-size: 34rpx;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;line-height: 80rpx;border: 1px solid #0094FE;">分享</button>

+ 14 - 1
miniprogram/pages/takePhoto/takePhoto.js

@@ -46,6 +46,7 @@ Page({
           latitude,
           longitude
         } = e
+        console.log("获取定位成功!", e)
         this.data.latitude = latitude
         this.data.longitude = longitude
         wx.setStorageSync('latitude', latitude)
@@ -54,6 +55,7 @@ Page({
           mediaType: ["image"],
           sourceType: ["camera"],
           success: e => {
+            console.log("获取媒体成功!", e)
             let src = e.tempFiles[0].tempFilePath
             if (e.type == "video") {
               wx.showLoading({
@@ -111,6 +113,7 @@ Page({
                 src,
                 quality: 80, // 压缩质量
                 success: async e => {
+                  console.log("图片压缩成功!", e)
                   wx.hideLoading({
                     success: (res) => {},
                   })
@@ -123,14 +126,17 @@ Page({
                       userId: wx.getStorageSync('userId'),
                       location: `${this.data.longitude},${this.data.latitude}`
                     })
+                    console.log("上传结束", res)
                     if (res.status == 0) {
                       wx.showToast({
                         title: res.msg
                       })
                       wx.setStorageSync('shareImageUrl', res.result.viewUrl)
+                      console.log(wx.getStorageSync('shareImageUrl'))
                       wx.downloadFile({
                         url: res.result.viewUrl,
                         success: e => {
+                          console.log("下载调用!", e)
                           wx.setStorageSync('cacheImage', e.tempFilePath)
                           wx.saveImageToPhotosAlbum({
                             filePath: e.tempFilePath,
@@ -143,6 +149,7 @@ Page({
                               }
                             },
                             fail: e => {
+                              console.log("失败4", e)
                               this.setData({
                                 authModal: true,
                                 modalText: "文件存储"
@@ -152,6 +159,9 @@ Page({
                           wx.navigateTo({
                             url: '/pages/takePhoto/success/success',
                           })
+                        },
+                        fail: e => {
+                          console.log("失败3", e)
                         }
                       })
 
@@ -172,10 +182,13 @@ Page({
                   }
                 },
                 fail: e => {
-                  console.log(e)
+                  console.log("失败2", e)
                 }
               })
             }
+          },
+          fail: e => {
+            console.log("失败1", e)
           }
         })
       },

+ 1 - 0
miniprogram/utils/wxUtils.js

@@ -8,6 +8,7 @@ function wxSetSessionKey() {
           JSCODE: res.code
         })
         wx.setStorageSync('session_key', res1.result.session_key)
+        wx.setStorageSync('openId', res1.result._openid)
         resolve({
           session_key: res1.result.session_key
         })

+ 1 - 1
project.config.json

@@ -2,7 +2,7 @@
   "miniprogramRoot": "miniprogram/",
   "cloudfunctionRoot": "cloudfunctions/",
   "setting": {
-    "urlCheck": false,
+    "urlCheck": true,
     "es6": true,
     "enhance": true,
     "postcss": true,

+ 1 - 1
project.private.config.json

@@ -39,7 +39,7 @@
         {
           "name": "",
           "pathName": "pages/share/share",
-          "query": "shareImageUrl=https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/pat/images/%E8%88%B9%E8%80%81%E5%A4%A7%23281636964041159.?sign%%%%%%q-sign-algorithm%3Dsha1%26q-ak%3DAKID4xb091cy4tRikV0EBrGOGsCF1WkhMlum%26q-sign-time%3D1636964041%3B93158697600%26q-key-time%3D1636964041%3B93158697600%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3Dfdcf8433880671a98cd69786dc8433cb97511116",
+          "query": "shareImageUrl=https://hhd-pat-1255802371.cos.ap-shanghai.myqcloud.com/pat/images/%E8%88%B9%E8%80%81%E5%A4%A7%23281637159182904.qwerdfb000mmmcccsign=q-sign-algorithm%3Dsha1%26q-ak%3DAKID4xb091cy4tRikV0EBrGOGsCF1WkhMlum%26q-sign-time%3D1637159183%3B93158697600%26q-key-time%3D1637159183%3B93158697600%26q-header-list%3Dhost%26q-url-param-list%3D%26q-signature%3D7b0a98a3e901fbffb82441bd4d00aad45361b5d0",
           "scene": 1007
         }
       ]