uniapp 微信小程序的支付
wxPay(oo) {
console.log(oo, 'ccc')
let that = this;
let obj = {
"agentId": that.agentId,
"cabinetId": that.cabinetId ? that.cabinetId : null,
"batteryType": that.infoData.batteryType,
"activityId": oo.hdID,
"priceId": oo.tcID,
"vipId": oo.vipPacketPeriodPriceId,
"price": oo.tcPrice,
"couponTicketId": oo.zjCouponID,
"insuranceId": oo.bxID,
"insurancePrice": oo.bxPrice,
selfDetailId:oo.selfDetailId, //套餐id
selfDetailDayCount:oo.selfDetailDayCount, //自定义套餐天数
}
if (that.total <= 0) {
that.yEPay(oo);
} else {
that.$axios.post(' create_by_weixin_ma.htm', obj).then((res) => {
console.log(res, '微信支付')
let myRes = res.data,
myData = myRes.data;
if (myRes.code == 0) {
uni.requestPayment({
provider: 'wxpay',
timeStamp: myData.timeStamp,
nonceStr: myData.nonceStr,
package: myData.package,
signType: myData.signType,
paySign: myData.paySign,
success(res) {
console.log(res, '充值成功')
that.successShow = true;
uni.$emit('cz', {
cz: 1
})
},
fail(res) {
console.log(res, '充值失败')
that.defeatedShow = true;
}
})
} else {
uni.showToast({
title: myRes.message,
icon: 'none'
})
}
}).catch((res) => {
console.log(res)
})
}
},
uniapp的手机号登录
<button type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" >
</button>
//授权回调
getPhoneNumber(res) {
if(res.detail.errMsg === 'getPhoneNumber:ok'){
const urls = '/jbs/mini/login/v1';
request
.handlerPost(urls, {
iv: res.detail.iv,
encryptedData: res.detail.encryptedData,
code: this.code
})
.then(res => {
if (res.success) {
uni.setStorageSync('thoken', res.data)
this.getUserInfo()
}
})
.catch(errMsg => {
console.log(errMsg);
});
}else{
console.log('拒绝')
}
},
封装请求方法
@params: {
method: 请求方式
url: 请求的url,
data: 携带的数据,
loading: 放在data里面,需要显示菊花加载就为true
}
@使用方法,挂载到vue-prototype上,
Vue.prototype.$ajax = ajax
*/
import gloabl from '../common/gloabl.js'
const request = (method, url, data, type) => { // type=9,无token请求
let httpUrl = gloabl.data.httpUrl
const promise = new Promise((resolve, reject) => {
// promise里面都可以处理任何错误捕捉,包括请求前,请求后
if (data && data.loading) {
uni.showLoading({
title: '加载中...',
mask: true
})
}
uni.request({
method,
url: httpUrl + url,
data,
header: {
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json, text/plain, */*',
Authorization: type == 9 ? '' : uni.getStorageSync('token')
},
success: (res) => {
if (res.data.code === 401) {
reject(res)
} else {
resolve(res)
}
if (data && data.loading) {
uni.hideLoading()
}
},
fail: (err) => {
reject(err)
let msg = err.errMsg
if (msg.indexOf('timeout') > -1) {
msg = '连接超时'
}
if (msg.indexOf('abort') > -1) {
msg = '连接终止'
}
uni.showToast({
title: msg || '网络错误!',
icon: 'none'
})
}
});
});
return promise
}
const ajax = {
get: (url, data, type) => {
return request('GET', url, data, type)
},
post: (url, data, type) => {
return request('POST', url, data, type)
},
put: (url, data, type) => {
return request('PUT', url, data, type)
},
del: (url, data, type) => {
return request('DELETE', url, data, type)
},
}
export {
ajax
}
后台管理系统上传图片
<el-upload
class="upload-demo uploadPictures"
:action="url+'/cargo/image/upload'"
:on-remove="handleRemoveB"
:headers="uploadHeader"
:data="myData"
:on-success="handleSuccessB"
:before-upload="beforeAvatarUpload"
:file-list="fileList"
list-type="picture"
accept=".jpg,.png,">
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超500kb</div>
</el-upload>
// 移除图片
handleRemoveB(file, fileList) {
// console.log(fileList)
const listBanner = [];
fileList.forEach((e) => {
listBanner.push(e.response.data.url);
});
this.goodsImg = listBanner;
},
// 上传封面图片
UploadCover(res, file, fileList) {
if (res.success) {
this.$message.success('上传新闻封面图片成功')
this.cover = res.data.url;
} else {
this.$message.warning(res.msg)
}
},
beforeAvatarUpload (file) {
const isLt2M = file.size / 1024 / 1024 < 2
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 2MB和视频!')
}
return isLt2M
},