cloud-function.vue 2.1 KB
Newer Older
d-u-a's avatar
d-u-a 已提交
1
<template>
study夏羽's avatar
study夏羽 已提交
2 3 4
	<view class="container">
		<view class="title">请求数据</view>
		<input class="input" v-model="inputValue" />
d-u-a's avatar
d-u-a 已提交
5

study夏羽's avatar
study夏羽 已提交
6 7 8 9 10 11 12 13 14
		<view class="group">
			<view class="secret-type">
				secretType: "both"
			</view>
			<view class="secret-type-comment">
				客户端和服务器上行下行数据都加密数据
			</view>
			<button type="primary" @click="getBySecretType('both')">get</button>
		</view>
d-u-a's avatar
d-u-a 已提交
15

study夏羽's avatar
study夏羽 已提交
16 17 18 19 20 21 22 23 24
		<view class="group">
			<view class="secret-type">
				secretType: "request"
			</view>
			<view class="secret-type-comment">
				只加密客户端请求时的上行数据,服务器下发数据不加密
			</view>
			<button type="primary" @click="getBySecretType('request')">get</button>
		</view>
d-u-a's avatar
d-u-a 已提交
25

study夏羽's avatar
study夏羽 已提交
26 27 28 29 30 31 32 33 34
		<view class="group">
			<view class="secret-type">
				secretType: "response"
			</view>
			<view class="secret-type-comment">
				客户端请求时不加密数据,只加密服务器下发的数据
			</view>
			<button type="primary" @click="getBySecretType('response')">get</button>
		</view>
d-u-a's avatar
d-u-a 已提交
35

study夏羽's avatar
study夏羽 已提交
36 37 38 39 40 41 42 43 44 45
		<view class="tips">
			提示:
			<view class="tips-item">
				当前请求的云函数强制校验 secretType: "both",返回值为请求的数据
			</view>
			<view class="tips-item">
				不管是客户端接收云端数据、还是云端接受客户端数据,开发者的代码拿到的数据永远都是解密后的数据
			</view>
		</view>
	</view>
d-u-a's avatar
d-u-a 已提交
46 47 48
</template>

<script>
study夏羽's avatar
study夏羽 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
	export default {
		data() {
			return {
				inputValue: 'uniCloud-secure-network'
			}
		},
		methods: {
			getBySecretType(secretType) {
				uni.showLoading({
					title: '处理中...'
				})
				uniCloud.callFunction({
					name: 'secure-network',
					data: {
						value: this.inputValue
					},
					secretType,
					success: (res) => {
						uni.showModal({
							content: JSON.stringify(res.result),
							showCancel: false
						})
					},
					fail: (err) => {
						uni.showModal({
							content: err.message,
							showCancel: false
						})
						console.error(err)
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			}
		}
	}
d-u-a's avatar
d-u-a 已提交
86 87 88
</script>

<style>
study夏羽's avatar
study夏羽 已提交
89
	@import url("css.css");
d-u-a's avatar
d-u-a 已提交
90
</style>