本地生活-营业执照上传到阿里云oss

This commit is contained in:
wangxiaowei 2024-06-18 17:42:36 +08:00
parent bbd617bcaa
commit fe07ee1cca
10 changed files with 640 additions and 50 deletions

@ -2,8 +2,6 @@ import request from '@/utils/request'
import {client} from '@/utils/tools'
//获取店铺列表
export function getShopList(params) {
return request.get('shop/getShopList', {params})
@ -89,4 +87,14 @@ export function apiInvoiceDetail(params) {
// 订单发票详情
export function apiOrderInvoiceDetail(params) {
return request.get("order/invoice", { params })
}
}
// 本地生活-模板ID
export function getLocalLifeTemplateId(params) {
return request.get("notice/getLocalLifeTemplateId")
}
// 本地生活-订阅消息
export function sendMsg(params) {
return request.get("notice/sendMsg")
}

@ -15,14 +15,26 @@
<u-field label="管辖网点号" v-model="form.dominationBankNo" label-width="160" placeholder="请输入管辖网点号" required />
</view>
<!-- 证件类型 -->
<!-- 商户证件类型 -->
<view class="apply-form-item" @tap="showCrftType1=true">
<u-field label="证件类型" v-model="crftType1Label" label-width="160" style="flex: 1;" placeholder="请选择证件类型"
<u-field label="商户证件类型" v-model="crftType1Label" label-width="160" style="flex: 1;" placeholder="请选择商户证件类型"
required disabled>
<u-icon name="arrow-right" slot="right" size="28" />
</u-field>
</view>
<!-- 上传图片 -->
<view class="apply-form-item">
<u-field label="营业执照" label-width="160" placeholder="请上传营业执照" :border-bottom="false"
required disabled />
<view class="apply-form-upload" @click="uploadImage" v-if="form.businessLicense">
<image :src="form.businessLicense"></image>
</view>
<view class="apply-form-upload" @click="uploadImage" v-else>
<u-icon name="plus" color="#e2e2e2" size="48" top="28"></u-icon>
</view>
</view>
<!-- 证件号码 -->
<view class="apply-form-item">
<u-field label="证件号码" v-model="form.crftNo1" label-width="160" placeholder="请输入证件号码" required />
@ -41,9 +53,9 @@
</u-field>
</view>
<!-- 法人/负责人名称 -->
<!-- 法人/负责人证件号 -->
<view class="apply-form-item">
<u-field label="法人名称" v-model="form.crftName2" label-width="160" placeholder="请输入法人/负责人证件号码" required />
<u-field label="法人证件号" v-model="form.crftNo2" label-width="160" placeholder="请输入法人/负责人证件号码" required />
</view>
<!-- 商户地址 -->
@ -201,15 +213,19 @@
<script>
import { mapActions, mapMutations, mapGetters } from 'vuex'
import { ossUpload } from '@/js_sdk/jason-alioss-upload/oss.js'
import {
getShopCategory,
shopApply
shopApply,
sendMsg,
getLocalLifeTemplateId
} from "@/api/shop"
import {
baseURL
} from '@/config/app'
import {
sendSms
sendSms,
getMnpNotice
} from '@/api/app'
import {
SMSType
@ -221,6 +237,7 @@
rgiNo: '',
dominationBankNo: '',
crftType1:'',
businessLicense: '',
crftNo1:'',
crftName2:'',
crftType2:'',
@ -232,11 +249,11 @@
postCode:'',
merconat:'',
mertel:'',
ebankConFlag:'',
shopHomeConFlag:'',
mcssAdminFlag:'',
ebankConFlag: 2,
shopHomeConFlag: 2,
mcssAdminFlag: 2,
postCode:'',
creditSwitch:'',
creditSwitch: 2,
accntType1:'',
accntNo1:'',
phone:'',
@ -335,7 +352,7 @@
},
// 是否开通商户之家
choseShopHomeConFlage(e) {
choseShopHomeConFlag(e) {
this.form.shopHomeConFlag = e;
},
@ -356,6 +373,21 @@
this.accntType1Label = label
},
// 上传营业执照
uploadImage(){
uni.chooseImage({
count: 1,
success: async (file) => {
const {success,data} = await ossUpload(file.tempFilePaths[0], file.tempFiles[0].path, 'local_life_bussines_license/')
if(success) {
this.form.businessLicense = data
} else {
uni.showToast({icon:'none', title: '上传失败'})
}
}
})
},
async getShopCategoryFun(e) {
const {
code,
@ -365,8 +397,9 @@
this.shopCategory = data
}
},
sendSmsFun() {
if(!this.$refs.uCode.canGetCode) return
if (!this.$refs.uCode.canGetCode) return
if (!this.form.mobile) {
this.$toast({
title: '请填写手机号信息'
@ -387,37 +420,86 @@
// 提交表单
async onSubmit() {
const {
form,
isAgree,
fileList
} = this
const submitObj = {
...form,
license: fileList
}
delete submitObj.clabel
if (!isAgree) return this.$toast({
title: '请先同意《入驻协议》'
})
const {
data,
code,
msg
} = await shopApply(submitObj)
if(code == 1) {
this.$toast({
title: msg
// #ifdef MP-WEIXIN
await this.getAuthMsg();
//#endif
setTimeout(async () => {
const {
data,
code,
msg
} = await sendMsg()
console.log('data =' , data)
console.log('code =' , code)
console.log('msg =' , msg)
}, 500)
return false;
// const {
// form,
// isAgree,
// fileList
// } = this
// const submitObj = this.form;
// Object.keys(submitObj).forEach((key) => {
// if (submitObj[key] === '') {
// this.$toast({
// title: '请完善上方表单信息'
// })
// return false;
// }
// })
// console.log(submitObj)
// return false;
// if (!isAgree) return this.$toast({
// title: '请先同意《入驻协议》'
// })
// // #ifdef MP-WEIXIN
// await this.getAuthMsg();
// //#endif
// const {
// data,
// code,
// msg
// } = await shopApply(submitObj)
// if(code == 1) {
// this.$toast({
// title: msg
// })
// setTimeout(() => {
// this.$Router.replace({
// path: '/bundle/pages/settled_result/settled_result',
// query: {
// id: data.id
// }
// })
// },1000)
// }
},
getAuthMsg() {
return new Promise(resolve => {
getLocalLifeTemplateId().then((res) => {
if (res.code == 1) {
uni.requestSubscribeMessage({
tmplIds: res.id,
success (res) {
console.log('suc', res)
},
fail(res) {
console.log(res.errMsg);
},
complete(res) {
console.log('com-', res)
resolve();
}
});
} else {
resolve();
}
})
setTimeout(() => {
this.$Router.replace({
path: '/bundle/pages/settled_result/settled_result',
query: {
id: data.id
}
})
},1000)
}
});
},
onSuccess(e) {
@ -489,6 +571,19 @@
margin-left: 12rpx;
padding: 4rpx 0;
}
.apply-form-upload {
width: 120rpx;
height: 120rpx;
text-align: center;
border: 1px solid #d2d2d2;
margin-left: 12rpx;
image {
width: 120rpx;
height: 120rpx;
}
}
.apply-form-item {
.send-code-btn {

@ -0,0 +1,131 @@
export const Base64 = {
// private property
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode: function(input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode: function(input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 encoding
_utf8_encode: function(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode: function(utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}

@ -0,0 +1,166 @@
const base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
// Crypto utilities
export const util = {
// Bit-wise rotate left
rotl: function (n, b) {
return (n << b) | (n >>> (32 - b));
},
// Bit-wise rotate right
rotr: function (n, b) {
return (n << (32 - b)) | (n >>> b);
},
// Swap big-endian to little-endian and vice versa
endian: function (n) {
// If number given, swap endian
if (n.constructor == Number) {
return util.rotl(n, 8) & 0x00FF00FF |
util.rotl(n, 24) & 0xFF00FF00;
}
// Else, assume array and swap all items
for (var i = 0; i < n.length; i++)
n[i] = util.endian(n[i]);
return n;
},
// Generate an array of any length of random bytes
randomBytes: function (n) {
for (var bytes = []; n > 0; n--)
bytes.push(Math.floor(Math.random() * 256));
return bytes;
},
// Convert a string to a byte array
stringToBytes: function (str) {
var bytes = [];
for (var i = 0; i < str.length; i++)
bytes.push(str.charCodeAt(i));
return bytes;
},
// Convert a byte array to a string
bytesToString: function (bytes) {
var str = [];
for (var i = 0; i < bytes.length; i++)
str.push(String.fromCharCode(bytes[i]));
return str.join("");
},
// Convert a string to big-endian 32-bit words
stringToWords: function (str) {
var words = [];
for (var c = 0, b = 0; c < str.length; c++, b += 8)
words[b >>> 5] |= str.charCodeAt(c) << (24 - b % 32);
return words;
},
// Convert a byte array to big-endian 32-bits words
bytesToWords: function (bytes) {
var words = [];
for (var i = 0, b = 0; i < bytes.length; i++, b += 8)
words[b >>> 5] |= bytes[i] << (24 - b % 32);
return words;
},
// Convert big-endian 32-bit words to a byte array
wordsToBytes: function (words) {
var bytes = [];
for (var b = 0; b < words.length * 32; b += 8)
bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
return bytes;
},
// Convert a byte array to a hex string
bytesToHex: function (bytes) {
var hex = [];
for (var i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
},
// Convert a hex string to a byte array
hexToBytes: function (hex) {
var bytes = [];
for (var c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
},
// Convert a byte array to a base-64 string
bytesToBase64: function (bytes) {
// Use browser-native function if it exists
if (typeof btoa == "function") return btoa(util.bytesToString(bytes));
var base64 = [],
overflow;
for (var i = 0; i < bytes.length; i++) {
switch (i % 3) {
case 0:
base64.push(base64map.charAt(bytes[i] >>> 2));
overflow = (bytes[i] & 0x3) << 4;
break;
case 1:
base64.push(base64map.charAt(overflow | (bytes[i] >>> 4)));
overflow = (bytes[i] & 0xF) << 2;
break;
case 2:
base64.push(base64map.charAt(overflow | (bytes[i] >>> 6)));
base64.push(base64map.charAt(bytes[i] & 0x3F));
overflow = -1;
}
}
// Encode overflow bits, if there are any
if (overflow != undefined && overflow != -1)
base64.push(base64map.charAt(overflow));
// Add padding
while (base64.length % 4 != 0) base64.push("=");
return base64.join("");
},
// Convert a base-64 string to a byte array
base64ToBytes: function (base64) {
// Use browser-native function if it exists
if (typeof atob == "function") return util.stringToBytes(atob(base64));
// Remove non-base-64 characters
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
var bytes = [];
for (var i = 0; i < base64.length; i++) {
switch (i % 4) {
case 1:
bytes.push((base64map.indexOf(base64.charAt(i - 1)) << 2) |
(base64map.indexOf(base64.charAt(i)) >>> 4));
break;
case 2:
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0xF) << 4) |
(base64map.indexOf(base64.charAt(i)) >>> 2));
break;
case 3:
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0x3) << 6) |
(base64map.indexOf(base64.charAt(i))));
break;
}
}
return bytes;
}
}

@ -0,0 +1,25 @@
import { util } from './crypto.js'
export function HMAC(hasher, message, key, options) {
const _blocksize = 16
// Allow arbitrary length keys
key = key.length > _blocksize * 4 ?
hasher(key, { asBytes: true }) :
util.stringToBytes(key);
// XOR keys with pad constants
var okey = key,
ikey = key.slice(0);
for (var i = 0; i < _blocksize * 4; i++) {
okey[i] ^= 0x5C;
ikey[i] ^= 0x36;
}
var hmacbytes = hasher(util.bytesToString(okey) +
hasher(util.bytesToString(ikey) + message, { asString: true }),
{ asBytes: true });
return options && options.asBytes ? hmacbytes :
options && options.asString ? util.bytesToString(hmacbytes) :
util.bytesToHex(hmacbytes);
}

@ -0,0 +1,69 @@
import { Base64 } from './base64.js'
import { util } from './crypto.js'
import { HMAC } from './hmac.js'
import { SHA1 } from './sha1.js'
// 下面这3个信息必填
const url = 'https://zjeloong.oss-cn-hangzhou.aliyuncs.com/'
const OSSAccessKeyId = 'LTAI5t5dcGDXvRSM9k2MAtqC'
const OssAccesskeySercet= 'X2cRzvWbtKpzSip8o3m8URJKFo1piJ';
const policyText = {
"expiration": "2034-01-01T12:00:00.000Z", // 设置Policy的有效期,格式为UTC时间。如果Policy失效,将无法上传文件。
"conditions": [
["content-length-range", 0, 1048576000] // 限制上传文件的大小,单位为字节,此处限制文件大小为1 GB。如果上传的文件大小超过此限制,文件将无法上传到OSS。如果未设置该限制,则默认文件大小最大为5 GB。
]
}
const policy = Base64.encode(JSON.stringify(policyText))
const bytes = HMAC(SHA1, policy, OssAccesskeySercet, { asBytes: true })
const signature = util.bytesToBase64(bytes)
// 生成文件名随机字符串
function random_string(len) {
  const strLeng = len || 32;
  const chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  const maxPos = chars.length;
  let pwd = '';
  for (let i = 0; i < strLeng; i++) {
  pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
// 获取文件后缀
function get_suffix(filename) {
const pos = filename.lastIndexOf('.')
let suffix = ''
if (pos != -1) {
suffix = filename.substring(pos)
}
return suffix;
}
// dir格式:'img/'
export const ossUpload = (filePath, name, dir) => {
const key = dir + random_string(10) + get_suffix(name)
return new Promise((resolve, reject) => {
uni.uploadFile({
url,
filePath,
name: 'file',
formData: {
name,
key,
policy,
OSSAccessKeyId,
success_action_status: '200',
signature
},
success: () => {
resolve({success: true, data: url+key})
},
fail: () => {
reject({success: false, data: '上传失败'})
}
})
})
}

@ -0,0 +1,20 @@
{
"id": "jason-alioss-upload",
"name": "阿里云存储OSS前端直接上传(全端通用) - 前端JASON",
"displayName": "阿里云存储OSS前端直接上传(全端通用) - 前端JASON",
"version": "1.0.0",
"description": "阿里云oss存储前端直传,不需要后端鉴权及签名;h5、小程序、app全端通用;支持vue2、vue3",
"keywords": [
"对象存储",
"oss",
"文件上传",
"阿里云",
"oss上传"
],
"dcloudext": {
"category": [
"JS SDK",
"通用 SDK"
]
}
}

@ -0,0 +1,64 @@
import { util } from './crypto.js'
// The core
function _sha1(message) {
var m = util.stringToWords(message),
l = message.length * 8,
w = [],
H0 = 1732584193,
H1 = -271733879,
H2 = -1732584194,
H3 = 271733878,
H4 = -1009589776;
// Padding
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >>> 9) << 4) + 15] = l;
for (var i = 0; i < m.length; i += 16) {
var a = H0,
b = H1,
c = H2,
d = H3,
e = H4;
for (var j = 0; j < 80; j++) {
if (j < 16) w[j] = m[i + j];
else {
var n = w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16];
w[j] = (n << 1) | (n >>> 31);
}
var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
(H1 ^ H2 ^ H3) - 899497514);
H4 = H3;
H3 = H2;
H2 = (H1 << 30) | (H1 >>> 2);
H1 = H0;
H0 = t;
}
H0 += a;
H1 += b;
H2 += c;
H3 += d;
H4 += e;
}
return [H0, H1, H2, H3, H4];
};
// Public API
export function SHA1(message, options) {
var digestbytes = util.wordsToBytes(_sha1(message));
return options && options.asBytes ? digestbytes :
options && options.asString ? util.bytesToString(digestbytes) :
util.bytesToHex(digestbytes);
};

@ -16,10 +16,13 @@
</image> -->
</router-link>
<view class="flex-1">
<router-link to="/pages/goods_search/goods_search">
<u-search wrap-bg-color="transparent" bg-color="#fff" :disabled="true" :height="62">
</u-search>
</router-link>
<view class="flex row">
<router-link to="/pages/goods_search/goods_search">
<u-search wrap-bg-color="transparent" bg-color="#fff" :disabled="true" :height="62">
</u-search>
</router-link>
<u-icon name="scan" size="44" color="#FFFFFF" @click="scanQRCode"></u-icon>
</view>
</view>
<!-- #ifdef MP -->
@ -220,6 +223,15 @@
this.$refs.mescrollItem.getData()
this.mescroll.endSuccess(0, false)
},
// 扫码
scanQRCode() {
uni.scanCode({
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
}
});
}
},
computed: {

@ -348,4 +348,4 @@ export function toLivePlayer(roomId) {
url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}`
})
}
// #endif
// #endif