wangzhihui 4 rokov pred
rodič
commit
293d1c8988
42 zmenil súbory, kde vykonal 1117 pridanie a 2 odobranie
  1. 11 2
      README.md
  2. 36 0
      cloudfunctions/api/WXBizDataCrypt.js
  3. 6 0
      cloudfunctions/api/config.json
  4. 95 0
      cloudfunctions/api/index.js
  5. 17 0
      cloudfunctions/api/package.json
  6. 17 0
      miniprogram/apis/api.js
  7. 22 0
      miniprogram/apis/apiConfig.js
  8. 9 0
      miniprogram/apis/cloudApi.js
  9. 37 0
      miniprogram/app.js
  10. 22 0
      miniprogram/app.json
  11. 26 0
      miniprogram/app.wxss
  12. 6 0
      miniprogram/envList.js
  13. BIN
      miniprogram/images/1.png
  14. BIN
      miniprogram/images/2.png
  15. BIN
      miniprogram/images/3.png
  16. BIN
      miniprogram/images/4.png
  17. BIN
      miniprogram/images/5.png
  18. BIN
      miniprogram/images/6.png
  19. BIN
      miniprogram/images/index.png
  20. 158 0
      miniprogram/pages/cachePage/cachePage.js
  21. 3 0
      miniprogram/pages/cachePage/cachePage.json
  22. 52 0
      miniprogram/pages/cachePage/cachePage.wxml
  23. 50 0
      miniprogram/pages/cachePage/cachePage.wxss
  24. 56 0
      miniprogram/pages/index/index.js
  25. 3 0
      miniprogram/pages/index/index.json
  26. 2 0
      miniprogram/pages/index/index.wxml
  27. 19 0
      miniprogram/pages/index/index.wxss
  28. 7 0
      miniprogram/pages/takePhoto/success/success.js
  29. 3 0
      miniprogram/pages/takePhoto/success/success.json
  30. 7 0
      miniprogram/pages/takePhoto/success/success.wxml
  31. 1 0
      miniprogram/pages/takePhoto/success/success.wxss
  32. 149 0
      miniprogram/pages/takePhoto/takePhoto.js
  33. 3 0
      miniprogram/pages/takePhoto/takePhoto.json
  34. 12 0
      miniprogram/pages/takePhoto/takePhoto.wxml
  35. 91 0
      miniprogram/pages/takePhoto/takePhoto.wxss
  36. 7 0
      miniprogram/sitemap.json
  37. 22 0
      miniprogram/utils/upload.js
  38. 47 0
      miniprogram/utils/wxUtils.js
  39. 69 0
      project.config.json
  40. 30 0
      project.private.config.json
  41. 1 0
      uploadCloudFunction.sh
  42. 21 0
      隐私协议.txt

+ 11 - 2
README.md

@@ -1,3 +1,12 @@
-# JiangYunPhotos_2.0_WxApp
+# 云开发 quickstart
+
+这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
+
+- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
+- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
+- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
+
+## 参考文档
+
+- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
 
-汇很多随手拍2.0

+ 36 - 0
cloudfunctions/api/WXBizDataCrypt.js

@@ -0,0 +1,36 @@
+var crypto = require('crypto')
+
+function WXBizDataCrypt(appId, sessionKey) {
+  this.appId = appId
+  this.sessionKey = sessionKey
+}
+
+WXBizDataCrypt.prototype.decryptData = function (encryptedData, iv) {
+  // base64 decode
+  var sessionKey = new Buffer(this.sessionKey, 'base64')
+  encryptedData = new Buffer(encryptedData, 'base64')
+  iv = new Buffer(iv, 'base64')
+
+  try {
+    // 解密
+    var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv)
+    // 设置自动 padding 为 true,删除填充补位
+    decipher.setAutoPadding(true)
+    // var decoded = decipher.update(encryptedData, 'binary', 'utf8')
+    var decoded = decipher.update(encryptedData, '', 'utf8')
+    decoded += decipher.final('utf8')
+
+    decoded = JSON.parse(decoded)
+
+  } catch (err) {
+    throw new Error('Illegal Buffer')
+  }
+
+  if (decoded.watermark.appid !== this.appId) {
+    throw new Error('Illegal Buffer')
+  }
+
+  return decoded
+}
+
+module.exports = WXBizDataCrypt

+ 6 - 0
cloudfunctions/api/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 95 - 0
cloudfunctions/api/index.js

@@ -0,0 +1,95 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+const TcbRouter = require("tcb-router")
+const got = require('got')
+const md5 = require("md5")
+const APPID = "wxf22759845920b6f3"
+const SECRET = "149873f78958781cd1693c1238deaebc"
+const WXBizDataCrypt = require('./WXBizDataCrypt')
+
+cloud.init()
+
+
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const wxContext = cloud.getWXContext()
+  const _openid = wxContext.OPENID
+
+  const app = new TcbRouter({
+    event
+  });
+
+  console.log('Event', event)
+
+  app.use(async (ctx, next) => {
+    ctx.data = {};
+    await next();
+  });
+
+
+  app.router("getWxPhoneNumber", async (ctx, next) => {
+    let {
+      cloudID,
+      encryptedData,
+      errMsg,
+      iv,
+      session_key
+    } = event
+    console.log(event)
+
+    let pc = new WXBizDataCrypt(APPID, session_key)
+
+    let data = pc.decryptData(encryptedData, iv)
+
+    ctx.body = {
+      phone: data.phoneNumber,
+      _openid
+    }
+    await next()
+  })
+
+  app.router("getOpenId", async (ctx, next) => {
+    ctx.body = {
+      openId: _openid
+    }
+    await next()
+  })
+
+  app.router("base", async (ctx, next) => {
+
+    await next()
+  })
+
+  app.router("code2Session", async (ctx, next) => {
+    let JSCODE = event.JSCODE
+    let url = `https://api.weixin.qq.com/sns/jscode2session?appid=${APPID}&secret=${SECRET}&js_code=${JSCODE}&grant_type=authorization_code`
+
+    let res = await got(url)
+    let result = JSON.parse(res.body)
+    ctx.body = {
+      ...result
+    }
+
+    await next()
+  })
+
+
+
+  app.router("getAccessToken", async (ctx, next) => {
+    let tokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${SECRET}`
+
+
+    let res = await got(tokenUrl)
+    let {
+      access_token
+    } = JSON.parse(res.body)
+    console.log(access_token)
+    ctx.data = {
+      access_token
+    }
+    await next();
+  });
+
+  return app.serve();
+}

+ 17 - 0
cloudfunctions/api/package.json

@@ -0,0 +1,17 @@
+{
+  "name": "api",
+  "version": "1.0.0",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.5.3",
+    "md5": "^2.3.0",
+    "got": "^11.8.2",
+    "tcb-router": "^1.1.2"
+  },
+  "description": ""
+}

+ 17 - 0
miniprogram/apis/api.js

@@ -0,0 +1,17 @@
+const {
+  api
+} = require("./apiConfig")
+
+function getApi(url, data) {
+  return api(url, data, "get")
+}
+
+function postApi(url, data) {
+  return api(url, data, "post")
+
+}
+
+module.exports = {
+  getApi,
+  postApi
+}

+ 22 - 0
miniprogram/apis/apiConfig.js

@@ -0,0 +1,22 @@
+let apiUrl = "https://interface.huihenduo.com.cn/hhd-pat/"
+
+function api(url, data, method) {
+  return new Promise((resolve, reject) => {
+    wx.request({
+      url: `${apiUrl}/${url}`,
+      method,
+      data,
+      dataType: 'json',
+      header: {
+        'content-type': 'application/json'
+      },
+      success: resolve,
+      fail: reject
+    })
+  })
+}
+
+module.exports = {
+  apiUrl,
+  api
+}

+ 9 - 0
miniprogram/apis/cloudApi.js

@@ -0,0 +1,9 @@
+module.exports = async function cloudApi($url, data) {
+  return await wx.cloud.callFunction({
+    name: "api",
+    data: {
+      $url,
+      ...data
+    }
+  })
+}

+ 37 - 0
miniprogram/app.js

@@ -0,0 +1,37 @@
+//app.js
+import {
+  wxSetSessionKey,
+} from "./utils/wxUtils"
+App({
+  onLaunch: function () {
+    const updateManager = wx.getUpdateManager()
+
+    updateManager.onCheckForUpdate(function (res) {
+      // 请求完新版本信息的回调
+    })
+
+    updateManager.onUpdateReady(function () {
+      wx.showModal({
+        title: '更新提示',
+        content: '新版本已经准备好,是否重启应用?',
+        success: function (res) {
+          if (res.confirm) {
+            // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
+            updateManager.applyUpdate()
+          }
+        }
+      })
+    })
+
+    updateManager.onUpdateFailed(function () {
+      // 新版本下载失败
+    })
+
+
+    wx.cloud.init({
+      traceUser: true
+    })
+    wxSetSessionKey()
+    this.globalData = {}
+  },
+})

+ 22 - 0
miniprogram/app.json

@@ -0,0 +1,22 @@
+{
+  "pages": [
+    "pages/index/index",
+    "pages/takePhoto/takePhoto",
+    "pages/cachePage/cachePage"
+  ],
+  "window": {
+    "backgroundColor": "#F6F6F6",
+    "backgroundTextStyle": "light",
+    "navigationBarBackgroundColor": "#F6F6F6",
+    "navigationBarTitleText": "云开发 QuickStart",
+    "navigationBarTextStyle": "black",
+    "navigationStyle": "custom"
+  },
+  "permission": {
+    "scope.userLocation": {
+      "desc": "你的位置信息将用于小程序位置接口的效果展示"
+    }
+  },
+  "sitemapLocation": "sitemap.json",
+  "style": "v2"
+}

+ 26 - 0
miniprogram/app.wxss

@@ -0,0 +1,26 @@
+page {
+  width: 100%;
+  height: 100%;
+}
+
+view {
+  box-sizing: border-box
+}
+
+.df {
+  display: flex;
+}
+
+.mt100 {
+  margin-top: 100rpx
+}
+
+.mb30 {
+  margin-bottom: 30rpx;
+}
+
+.line {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}

+ 6 - 0
miniprogram/envList.js

@@ -0,0 +1,6 @@
+const envList = [{"envId":"huihenduo-0gwuxs6d1c6824e4","alias":"huihenduo"}]
+const isMac = true
+module.exports = {
+    envList,
+    isMac
+}

BIN
miniprogram/images/1.png


BIN
miniprogram/images/2.png


BIN
miniprogram/images/3.png


BIN
miniprogram/images/4.png


BIN
miniprogram/images/5.png


BIN
miniprogram/images/6.png


BIN
miniprogram/images/index.png


+ 158 - 0
miniprogram/pages/cachePage/cachePage.js

@@ -0,0 +1,158 @@
+// pages/cachePage/cachePage.js
+import cloudApi from "../../apis/cloudApi"
+import {
+  postApi
+} from "../../apis/api"
+import {
+  uploadFile
+} from "../../utils/upload"
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    type: "",
+    file: "",
+    latitude: "",
+    longitude: "",
+    shipName: "",
+    shipMmsi: "",
+    agreeModal: false,
+    agreeText: false
+  },
+  goBack() {
+    wx.navigateTo({
+      url: '/pages/index/index',
+    })
+  },
+  checkout() {
+    if (!this.data.shipName) {
+      wx.showToast({
+        title: '请输入船名!',
+        icon: "error"
+      })
+      return
+    }
+
+    if (!this.data.shipMmsi) {
+      wx.showToast({
+        title: '请输入MMSI!',
+        icon: "error"
+      })
+      return
+    }
+
+    return true
+  },
+  agree() {
+    this.setData({
+      agreeText: false,
+    })
+  },
+
+  showAgeeeText() {
+    this.setData({
+      agreeText: true
+    })
+  },
+  hideAgreeText() {
+    this.setData({
+      agreeText: false
+    })
+  },
+  hideAgreeModal() {
+    this.setData({
+      agreeModal: false
+    })
+  },
+  showAgreeModal() {
+    if (!this.checkout()) return
+    this.setData({
+      agreeModal: true
+    })
+  },
+  async getPhoneNumber(e) {
+    if (e.detail.errMsg == "getPhoneNumber:ok") {
+      wx.showLoading({
+        title: '正在登录...',
+      })
+      let session_key = wx.getStorageSync('session_key')
+      let {
+        result
+      } = await cloudApi("getWxPhoneNumber", {
+        ...e.detail,
+        session_key
+      })
+
+      let {
+        phone,
+      } = result
+      let {
+        shipName,
+        shipMmsi
+      } = this.data
+
+      console.log(phone,
+        shipName,
+        shipMmsi, )
+      let res = await uploadFile(wx.getStorageSync('file'), {
+        openId: wx.getStorageSync('openId'),
+        phone,
+        shipName,
+        shipMmsi,
+        type: wx.getStorageSync('type'),
+        location: `${this.data.longitude},${this.data.latitude}`
+      }, 1)
+      console.log(res)
+      if (res.status == 0) {
+        let {
+          shipInfo,
+          userInfo
+        } = res.result
+
+        let data = {
+          ...shipInfo,
+          ...userInfo
+        }
+        Object.keys(data).forEach(function (key) {
+          wx.setStorageSync(key, data[key])
+        })
+        wx.showToast({
+          title: res.msg,
+        })
+        wx.navigateTo({
+          url: '/pages/takePhoto/takePhoto',
+        })
+      } else {
+        wx.showToast({
+          title: res.msg,
+          icon: "error"
+        })
+      }
+    } else {
+      wx.showToast({
+        title: '请授权以登录',
+        icon: "error"
+      })
+    }
+
+
+  },
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    this.setData({
+      type: wx.getStorageSync('type'),
+      file: wx.getStorageSync('file'),
+      latitude: wx.getStorageSync('latitude'),
+      longitude: wx.getStorageSync('longitude')
+    })
+  },
+
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
miniprogram/pages/cachePage/cachePage.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 52 - 0
miniprogram/pages/cachePage/cachePage.wxml

@@ -0,0 +1,52 @@
+<view class="main-container">
+  <image class="media-container" mode="aspectFit" wx:if="{{type==1}}" src="{{file}}"> </image>
+  <video class="media-container" autoplay="{{true}}" wx:else src="{{file}}"></video>
+</view>
+<view class="line mb30">
+  <view class="ship-name">船舶名称 : </view><input class="ship-name-ipt" model:value="{{shipName}}" type="text" placeholder="请输入船舶名称" />
+</view>
+<view class="line">
+  <view class="ship-mmsi">MMSI : </view><input class="ship-mmsi-ipt" model:value="{{shipMmsi}}" type="text" placeholder="请输入MMSI" />
+</view>
+<view>
+  <button style="width: 600rpx;height: 90rpx;line-height: 90rpx;background: #3e94f6;border-radius: 45rpx;padding: 0;margin-top: 30rpx;" bindtap="showAgreeModal" type="primary">手机号登录</button>
+  <button style="width: 500rpx;height: 60rpx;line-height: 60rpx;background: #777;border-radius: 30rpx;padding: 0;margin-top: 30rpx;font-size: 24rpx;" bindtap="goBack" type="primary">返回继续体验</button>
+</view>
+<view wx:if="{{agreeText}}" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(000, 000, 000, 0.5);z-index: 10;">
+  <scroll-view style="height: 90vh;width: 90vw;background-color: #fff;margin: 5vh auto;padding: 20rpx;" scroll-y="true">
+    <view style="font-size:large;text-align: center;margin:60rpx;">隐私协议</view>
+    <text space="ensp" decode="true">&nbsp;&nbsp;</text>
+    <text space="ensp" decode="true">&nbsp;&nbsp;本隐私政策介绍本公司的隐私数据相关政策和惯例,包括在使用汇很多小程序时上传至云端的数据将受到保护,防止以及追究某些非法手段获取本公司所保管的关于您的数据资料。请你仔细阅读我们的隐私政策。
+    </text><text space="ensp" decode="true">一、本公司如何收集您的个人信息汇很多小程序以个人电话号码作为唯一身份识别方式,用于个人登录使用以及密码遗忘、找回的唯一途径。当您使用本公司的微信小程序,注册过程中我们将仅收集您的电话号码作为唯一身份识别,使用期间终身有效。
+    </text><text space="ensp" decode="true">二、本公司如何使用您的个人信息
+      1、通过您的手机号码实现密码找回功能。
+      2、本公司不会向任何无关第三方提供、出售、出租、分享或交易您的个人信息,除非事先得到您的许可,或该第三方和本公司单独或共同为您提供服务,且在该服务结束后,其将被禁止访问包括其以前能够访问的所有这些信息。
+    </text><text space="ensp" decode="true">三、个人信息安全
+      保证您的数据的安全对我们来说至关重要。当您在本公司的微信小程序中注册输入个人信息时,我们对这些信息进行加密。
+      在数据传输和数据保管两个阶段里,我们会通过广为接受的行业标准(如防火墙、加密和数据隐私法律要求)来保护您向我们提交的信息。
+      然而,没有任何一种互联网传输或电子存储方法是100%安全的。因此,尽管我们通过商业上可接受的方式来保护您的个人信息,但仍无法保证信息的绝对安全。
+    </text><text space="ensp" decode="true">四、本公司会将个人信息保存多久
+      一般来说,本公司仅在您使用本公司微信小程序期间保留您的个人信息,同时将遵守适用法律规定的数据保留期限。
+    </text><text space="ensp" decode="true">五、法律免责声明
+      在法律要求的情况下(如协助公安机关)或遵守司法程序、法院指令,以及因用户行为而致使本公司的法定权益收到威胁,或适用于本公司的微信小程序的法律程序时,我们有权透露您的个人信息。
+      如果本公司确定为了执行本公司的条款和条件或保护我们的经营,披露是合理必须的,则我们可能会披露与您有关的信息。
+    </text><text space="ensp" decode="true">六、本隐私政策的更改
+      本公司会根据国家法律法规不定时更改本政策协议。修改执行之前,本公司将会在小程序用户协议、以及本公司网站通知本次政策更改,以便您了解我们如何收集、使用您的个人信息,哪些人可以访问这些信息,以及在什么情况下我们会披露这些信息。
+      本公司保留随时修改本政策的权利,因此请经常查看。
+    </text><text space="ensp" decode="true">七、隐私问题
+      如果你对本公司的隐私政策或数据处理有任何问题或顾虑,请通过+86 18049981341与本公司联系。
+    </text>
+
+    <button bindtap="agree" type="primary">确定</button>
+  </scroll-view>
+</view>
+<view style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(000, 000, 000, 0.5);z-index: 8;" wx:if="{{agreeModal}}">
+  <view style="width:80vw;height:60vw;background:#fff;border-radius: 50rpx;padding: 50rpx;color: #333;font-size: 30rpx;margin: 60% auto;">
+    <view style="text-align: center;font-size: 36rpx;margin-bottom:20rpx ;">隐私协议提示</view>
+    <view>感谢您的信任并使用汇很多小程序,请务必阅读 <text bindtap="showAgeeeText" style="text-decoration: underline;color: orange;">《隐私协议》</text>各条款,若继续使用请点击下方按钮“同意并继续”。</view>
+    <view style="display: flex;justify-content: space-around;align-items: center;margin-top: 50rpx;">
+      <view style="width: 200rpx;height:80rpx;background: #eee;border-radius: 40rpx;text-align: center;line-height: 80rpx;color: #000;font-size: 28rpx;margin:0" bindtap="hideAgreeModal">取消</view>
+      <button style="    width: 200rpx;height: 80rpx;background: #333;border-radius: 40rpx;text-align: center;line-height: 80rpx;color: #fff;font-size: 28rpx;font-weight: normal;padding: 0;margin: 0;" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">同意并继续</button>
+    </view>
+  </view>
+</view>

+ 50 - 0
miniprogram/pages/cachePage/cachePage.wxss

@@ -0,0 +1,50 @@
+/* pages/cachePage/cachePage.wxss */
+.main-container {
+  height: 55vh;
+  width: 80vw;
+  margin: 0 auto;
+  margin-top: 10vh;
+  margin-bottom: 3vh;
+}
+
+.media-container {
+  width: 100%;
+  height: 100%;
+}
+
+
+
+.ship-name,
+.ship-mmsi {
+  width: 153rpx;
+  height: 36rpx;
+  font-size: 30rpx;
+  font-family: PingFangSC-Regular,
+    PingFang SC;
+  font-weight: 400;
+  color: #333333;
+  line-height: 36rpx;
+  text-align: right;
+  margin-right: 6rpx;
+}
+
+.ship-name-ipt,
+.ship-mmsi-ipt {
+  width: 420rpx;
+  height: 67rpx;
+  border: 1px solid #979797;
+  font-size: 30rpx;
+  padding-left: 20rpx;
+}
+
+.submit {
+  margin-top: 130rpx;
+  height: 80rpx;
+  background: #0094FE;
+  border-radius: 4rpx;
+  font-size: 34rpx;
+  font-family: PingFangSC-Regular,
+    PingFang SC;
+  font-weight: 400;
+  color: #FFFFFF;
+}

+ 56 - 0
miniprogram/pages/index/index.js

@@ -0,0 +1,56 @@
+// pages/index/index.js
+import cloudApi from "../../apis/cloudApi"
+import {
+  postApi
+} from "../../apis/api"
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+  go() {
+    wx.navigateTo({
+      url: '/pages/takePhoto/takePhoto',
+    })
+  },
+  async getOpenid() {
+    let res = await cloudApi("getOpenId")
+    let {
+      openId
+    } = res.result
+    wx.setStorageSync('openId', openId)
+    let res1 = await postApi("/user/wx/login", {
+      openId
+    })
+    console.log(res1)
+
+    if (res1.data.status == 0) {
+      let data = {
+        ...res1.data.result.userInfo,
+        ...res1.data.result.shipInfo,
+      }
+      Object.keys(data).forEach(function (key) {
+        wx.setStorageSync(key, data[key])
+      })
+      wx.navigateTo({
+        url: '/pages/takePhoto/takePhoto',
+      })
+    } else {
+
+    }
+
+  },
+  onLoad: function (options) {
+    this.getOpenid()
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
miniprogram/pages/index/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 2 - 0
miniprogram/pages/index/index.wxml

@@ -0,0 +1,2 @@
+<image class="main" mode="aspectFit" src="../../images/index.png"></image>
+<view bindtap="go" class="go">去体验</view>

+ 19 - 0
miniprogram/pages/index/index.wxss

@@ -0,0 +1,19 @@
+/* pages/index/index.wxss */
+.main {
+  display: block;
+  width: 80vw;
+  height: 60vh;
+  margin: 10vh auto;
+}
+
+.go {
+  width: 70vw;
+  height: 12vw;
+  line-height: 12vw;
+  font-size: 5vw;
+  text-align: center;
+  background: #3e94f6;
+  color: #fff;
+  border-radius: 6vw;
+  margin: 60rpx auto
+}

+ 7 - 0
miniprogram/pages/takePhoto/success/success.js

@@ -0,0 +1,7 @@
+Page({
+  go() {
+    wx.navigateTo({
+      url: '/pages/takePhoto/takePhoto',
+    })
+  }
+})

+ 3 - 0
miniprogram/pages/takePhoto/success/success.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 7 - 0
miniprogram/pages/takePhoto/success/success.wxml

@@ -0,0 +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>
+<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>
+<view bindtap="go" style="margin:0 auto;margin-top:40rpx;width: 650rpx;height: 80rpx;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;">返回</view>

+ 1 - 0
miniprogram/pages/takePhoto/success/success.wxss

@@ -0,0 +1 @@
+/* pages/takePhoto/success/success.wxss */

+ 149 - 0
miniprogram/pages/takePhoto/takePhoto.js

@@ -0,0 +1,149 @@
+import {
+  uploadFile
+} from "../../utils/upload"
+Page({
+  data: {
+    avatar: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/avatar-icon.jpg?sign=f5c66c94d189436f82353eb48cb01f08&t=1634538864",
+    cameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera-icon.png?sign=11a65871a2800cd04ecaa8991687fccd&t=1634607415",
+    userName: "",
+    phone: "",
+    shipName: "",
+    shipMmsi: "",
+    locationModal: false
+  },
+  openSetting() {
+    this.setData({
+      locationModal: false
+    })
+    wx.openSetting({})
+  },
+  takePhoto() {
+    wx.getLocation({
+      success: e => {
+        let {
+          latitude,
+          longitude
+        } = e
+        this.data.latitude = latitude
+        this.data.longitude = longitude
+        wx.setStorageSync('latitude', latitude)
+        wx.setStorageSync('longitude', longitude)
+        wx.chooseMedia({
+          // sourceType: ["camera", "album"],
+          sourceType: ["camera"],
+          success: e => {
+            let src = e.tempFiles[0].tempFilePath
+            if (e.type == "video") {
+              wx.showLoading({
+                title: '正在压缩...',
+              })
+              wx.compressVideo({
+                src,
+                quality: "high",
+                bitrate: "",
+                fps: "",
+                resolution: "",
+                success: async e => {
+                  if (wx.getStorageSync('userName')) {
+                    wx.showLoading({
+                      title: '正在上传...',
+                    })
+                    let res = await uploadFile(e.tempFilePath, {
+                      type: 4,
+                      userId: wx.getStorageSync('userId'),
+                      location: `${this.data.longitude},${this.data.latitude}`
+                    })
+                    if (res.status == 0) {
+                      wx.showToast({
+                        title: res.msg
+                      })
+                      wx.navigateTo({
+                        url: '/pages/takePhoto/success/success',
+                      })
+                    } else {
+                      wx.showToast({
+                        title: res.msg
+                      })
+                    }
+                  } else {
+                    // 新用户视频
+                    wx.hideLoading({
+                      success: (res) => {},
+                    })
+                    console.log("新用户视频", e)
+                    wx.setStorageSync('type', 2)
+                    wx.setStorageSync('file', e.tempFilePath)
+                    wx.navigateTo({
+                      url: `/pages/cachePage/cachePage`,
+                    })
+                  }
+
+                },
+                fail: e => {
+                  console.log(e)
+                }
+              })
+            } else {
+              wx.compressImage({
+                src,
+                quality: 80, // 压缩质量
+                success: async e => {
+                  wx.hideLoading({
+                    success: (res) => {},
+                  })
+                  if (wx.getStorageSync('userName')) {
+                    wx.showLoading({
+                      title: '正在上传...',
+                    })
+                    let res = await uploadFile(e.tempFilePath, {
+                      type: 3,
+                      userId: wx.getStorageSync('userId'),
+                      location: `${this.data.longitude},${this.data.latitude}`
+                    })
+                    if (res.status == 0) {
+                      wx.showToast({
+                        title: res.msg
+                      })
+                      wx.navigateTo({
+                        url: '/pages/takePhoto/success/success',
+                      })
+                    } else {
+                      wx.showToast({
+                        title: res.msg
+                      })
+                    }
+                  } else {
+                    // 新用户图片
+                    console.log("新用户图片", e)
+                    wx.setStorageSync('type', 1)
+                    wx.setStorageSync('file', e.tempFilePath)
+                    wx.navigateTo({
+                      url: `/pages/cachePage/cachePage`,
+                    })
+                  }
+                },
+                fail: e => {
+                  console.log(e)
+                }
+              })
+            }
+          }
+        })
+      },
+      fail: e => {
+        this.setData({
+          locationModal: true
+        })
+      }
+    })
+
+  },
+  onLoad() {
+    let userName = wx.getStorageSync('userName')
+    let phone = wx.getStorageSync('phone')
+    this.setData({
+      userName,
+      phone
+    })
+  }
+})

+ 3 - 0
miniprogram/pages/takePhoto/takePhoto.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 12 - 0
miniprogram/pages/takePhoto/takePhoto.wxml

@@ -0,0 +1,12 @@
+<view class="top-container">
+  <image class="avatar-icon" src="{{avatar}}"></image>
+  <view class="text" style="text-align: center;">{{userName?"":"体验用户"}}<text wx:if="{{userName}}" class="user-name">{{userName}}</text><text wx:if="{{phone}}" class="phone">{{phone}}</text></view>
+</view>
+<image class="camera-icon" bindtap="takePhoto" src="{{cameraIcon}}"></image>
+
+<view class="auth-modal" wx:if="{{locationModal}}">
+  <view class="modal">
+    <view class="service">为了更好的提供服务</view>
+    <view class="auth-btn" bindtap="openSetting">请授权位置信息</view>
+  </view>
+</view>

+ 91 - 0
miniprogram/pages/takePhoto/takePhoto.wxss

@@ -0,0 +1,91 @@
+/* pages/takePhoto/takePhoto.wxss */
+.top-container {
+  position: relative;
+  width: 100%;
+  height: 35vh;
+  padding-top: 154rpx;
+  background-size: contain;
+  background: url(https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/sea-bgd.jpeg?sign=f138978877f53ccdc48937c58811659b&t=1634539269)
+}
+
+.avatar-icon {
+  display: block;
+  width: 110rpx;
+  height: 110rpx;
+  border-radius: 50%;
+  margin: 0 auto;
+}
+
+.user-name {
+  margin-right: 40rpx;
+}
+
+.phone {
+  font-size: 28rpx;
+  font-weight: 400;
+}
+
+.text {
+  font-size: 30rpx;
+  font-family: PingFangSC-Medium,
+    PingFang SC;
+  font-weight: 500;
+  color: #FFFFFF;
+  margin-top: 30rpx;
+}
+
+
+
+.camera-icon {
+  display: block;
+  width: 234rpx;
+  height: 234rpx;
+  position: absolute;
+  top: 50%;
+  left: calc(50% - 117rpx);
+}
+
+.auth-modal {
+  position: absolute;
+  top: 0;
+  right: 0;
+  bottom: 0;
+  left: 0;
+  background-color: rgba(0, 0, 0, 0.7);
+}
+
+.modal {
+  width: 557rpx;
+  height: 274rpx;
+  background: #FFFFFF;
+  border-radius: 16rpx;
+  margin: 548rpx auto;
+  padding-top: 55rpx;
+}
+
+.service {
+  width: 100%;
+  text-align: center;
+  font-size: 36rpx;
+  font-family: PingFangSC-Medium,
+    PingFang SC;
+  font-weight: 500;
+  color: #333333;
+  -webkit-text-stroke: 1rpx #979797;
+}
+
+.auth-btn {
+  width: 350rpx;
+  height: 69rpx;
+  background: #0094FE;
+  border-radius: 8rpx;
+  font-size: 36rpx;
+  font-family: PingFangSC-Regular,
+    PingFang SC;
+  font-weight: 400;
+  color: #FFFFFF;
+  line-height: 69rpx;
+  margin: 0 auto;
+  margin-top: 55rpx;
+  text-align: center;
+}

+ 7 - 0
miniprogram/sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+    "action": "allow",
+    "page": "*"
+  }]
+}

+ 22 - 0
miniprogram/utils/upload.js

@@ -0,0 +1,22 @@
+import {
+  apiUrl
+} from "../apis/apiConfig"
+
+function uploadFile(filePath, formData, type) {
+  return new Promise((resolve, reject) => {
+    wx.uploadFile({
+      url: `${apiUrl}${type?"/user/wx/oneStepLogin":"/cos/upload"}`,
+      filePath,
+      name: 'file',
+      formData,
+      success: e => {
+        resolve(JSON.parse(e.data))
+      },
+      fail: reject
+    })
+  })
+}
+
+module.exports = {
+  uploadFile
+}

+ 47 - 0
miniprogram/utils/wxUtils.js

@@ -0,0 +1,47 @@
+import cloudApi from "../apis/cloudApi"
+
+function wxSetSessionKey() {
+  return new Promise((resolve, reject) => {
+    wx.login({
+      success: async res => {
+        let res1 = await cloudApi('code2Session', {
+          JSCODE: res.code
+        })
+        wx.setStorageSync('session_key', res1.result.session_key)
+        resolve({
+          session_key: res1.result.session_key
+        })
+      }
+    })
+  })
+
+}
+
+function getUserProfile() {
+  return new Promise((resolve, reject) => {
+    wx.getUserProfile({
+      desc: "'用于完善用户信息",
+      success: e => {
+        let {
+          userInfo
+        } = e
+        resolve({
+          status: 0,
+          userInfo
+        })
+      },
+      fail: e => {
+        resolve({
+          errMsg: e.errMsg,
+          status: 1
+        })
+      }
+    })
+  })
+}
+
+
+module.exports = {
+  wxSetSessionKey,
+  getUserProfile,
+}

+ 69 - 0
project.config.json

@@ -0,0 +1,69 @@
+{
+  "miniprogramRoot": "miniprogram/",
+  "cloudfunctionRoot": "cloudfunctions/",
+  "setting": {
+    "urlCheck": false,
+    "es6": true,
+    "enhance": true,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "newFeature": true,
+    "coverView": true,
+    "nodeModules": false,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "scopeDataCheck": false,
+    "uglifyFileName": false,
+    "checkInvalidKey": true,
+    "checkSiteMap": true,
+    "uploadWithSourceMap": true,
+    "compileHotReLoad": false,
+    "lazyloadPlaceholderEnable": false,
+    "useMultiFrameRuntime": true,
+    "useApiHook": true,
+    "useApiHostProcess": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    },
+    "enableEngineNative": false,
+    "useIsolateContext": true,
+    "userConfirmedBundleSwitch": false,
+    "packNpmManually": false,
+    "packNpmRelationList": [],
+    "minifyWXSS": true,
+    "disableUseStrict": false,
+    "minifyWXML": true,
+    "showES6CompileOption": false,
+    "useCompilerPlugins": false
+  },
+  "appid": "wxf22759845920b6f3",
+  "projectname": "%E6%B1%9F%E8%BF%90%E9%9A%8F%E6%89%8B%E6%8B%8D2.0",
+  "libVersion": "2.14.1",
+  "cloudfunctionTemplateRoot": "cloudfunctionTemplate",
+  "condition": {
+    "search": {
+      "list": []
+    },
+    "conversation": {
+      "list": []
+    },
+    "plugin": {
+      "list": []
+    },
+    "game": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": [
+        {
+          "id": -1,
+          "name": "db guide",
+          "pathName": "pages/databaseGuide/databaseGuide"
+        }
+      ]
+    }
+  }
+}

+ 30 - 0
project.private.config.json

@@ -0,0 +1,30 @@
+{
+  "setting": {},
+  "condition": {
+    "plugin": {
+      "list": []
+    },
+    "game": {
+      "list": []
+    },
+    "gamePlugin": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": [
+        {
+          "name": "pages/test/test",
+          "pathName": "pages/test/test",
+          "query": "",
+          "scene": null
+        },
+        {
+          "name": "缓存注册船舶",
+          "pathName": "pages/cachePage/cachePage",
+          "query": "",
+          "scene": null
+        }
+      ]
+    }
+  }
+}

+ 1 - 0
uploadCloudFunction.sh

@@ -0,0 +1 @@
+"/Applications/wechatwebdevtools.app/Contents/MacOS/cli" cloud functions deploy --e huihenduo-0gwuxs6d1c6824e4 --n quickstartFunctions --r --project "/Users/wangzhihui/Desktop/汇很多/weapp/JiangYunPhotos" --report_first --report

+ 21 - 0
隐私协议.txt

@@ -0,0 +1,21 @@
+本隐私政策介绍本公司的隐私数据相关政策和惯例,包括在使用汇很多小程序时上传至云端的数据将受到保护,防止以及追究某些非法手段获取本公司所保管的关于您的数据资料。请你仔细阅读我们的隐私政策。
+一、本公司如何收集您的个人信息
+汇很多小程序以个人电话号码作为唯一身份识别方式,用于个人登录使用以及密码遗忘、找回的唯一途径。
+当您使用本公司的微信小程序,注册过程中我们将仅收集您的电话号码作为唯一身份识别,使用期间终身有效。
+二、本公司如何使用您的个人信息
+1、通过您的手机号码实现密码找回功能。
+2、本公司不会向任何无关第三方提供、出售、出租、分享或交易您的个人信息,除非事先得到您的许可,或该第三方和本公司单独或共同为您提供服务,且在该服务结束后,其将被禁止访问包括其以前能够访问的所有这些信息。
+三、个人信息安全
+保证您的数据的安全对我们来说至关重要。当您在本公司的微信小程序中注册输入个人信息时,我们对这些信息进行加密。
+在数据传输和数据保管两个阶段里,我们会通过广为接受的行业标准(如防火墙、加密和数据隐私法律要求)来保护您向我们提交的信息。
+然而,没有任何一种互联网传输或电子存储方法是100%安全的。因此,尽管我们通过商业上可接受的方式来保护您的个人信息,但仍无法保证信息的绝对安全。
+四、本公司会将个人信息保存多久
+一般来说,本公司仅在您使用本公司微信小程序期间保留您的个人信息,同时将遵守适用法律规定的数据保留期限。
+五、法律免责声明
+在法律要求的情况下(如协助公安机关)或遵守司法程序、法院指令,以及因用户行为而致使本公司的法定权益收到威胁,或适用于本公司的微信小程序的法律程序时,我们有权透露您的个人信息。
+如果本公司确定为了执行本公司的条款和条件或保护我们的经营,披露是合理必须的,则我们可能会披露与您有关的信息。
+六、本隐私政策的更改
+本公司会根据国家法律法规不定时更改本政策协议。修改执行之前,本公司将会在小程序用户协议、以及本公司网站通知本次政策更改,以便您了解我们如何收集、使用您的个人信息,哪些人可以访问这些信息,以及在什么情况下我们会披露这些信息。
+本公司保留随时修改本政策的权利,因此请经常查看。
+七、隐私问题
+如果你对本公司的隐私政策或数据处理有任何问题或顾虑,请通过+86 18049981341与本公司联系。