|
@@ -3,14 +3,14 @@
|
|
|
<view class="margin-top" style="padding: 0 30rpx;">
|
|
|
<view class="title">选择兑换平台</view>
|
|
|
<view class="flex" style="justify-content: space-between; margin: 20rpx 0;">
|
|
|
- <view class="module" :class="{ selected: selectedModule === 'douyin' }" @click="selectModule('douyin')">
|
|
|
+ <view class="module" :class="{ selected: selectedModule === 1 }" @click="selectModule(1)">
|
|
|
<image v-if="globalImages" :src="globalImages + 'images/my/douyin.png'" style="width: 100rpx;height: 100rpx;" mode="">
|
|
|
</image>
|
|
|
<view style="font-size: 33rpx;margin-top: 20rpx;">抖音兑换码</view>
|
|
|
<view style="font-size: 23rpx; color: #999;margin-top: 10rpx;">输入抖音兑换码领取奖励</view>
|
|
|
</view>
|
|
|
- <view class="module" :class="{ selected2: selectedModule === 'kuaishou' }"
|
|
|
- @click="selectModule('kuaishou')">
|
|
|
+ <view class="module" :class="{ selected2: selectedModule === 2 }"
|
|
|
+ @click="selectModule(2)">
|
|
|
<image v-if="globalImages" :src="globalImages + 'images/my/kuaishou.png'" style="width: 100rpx;height: 100rpx;" mode="">
|
|
|
</image>
|
|
|
<view style="font-size: 33rpx;margin-top: 20rpx;">快手兑换码</view>
|
|
@@ -25,9 +25,9 @@
|
|
|
<view class="margin-top padding" style="background: #FFFFFF;border-radius: 20upx;">
|
|
|
<view class="flex"
|
|
|
style="margin: 20rpx 0; padding: 20rpx;border-radius: 11rpx; border: 1px #ccc solid;">
|
|
|
- <input class="uni-input" style="width: 90%;" placeholder="请输入兑换码" />
|
|
|
+ <input class="uni-input" style="width: 90%;" placeholder="请输入兑换码" v-model="exchangeCode" />
|
|
|
<image v-if="globalImages" :src="globalImages + 'images/saoma.png'" style="width: 44rpx;height: 44rpx;margin-left: 15rpx;"
|
|
|
- mode=""></image>
|
|
|
+ mode="" @click="scanQRCode"></image>
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="margin-top padding" style="background: #FFFFFF;border-radius: 20upx;">
|
|
@@ -56,7 +56,7 @@
|
|
|
<li class="notice-item">如有问题请联系客服 400 - 123 - 4567</li>
|
|
|
</ul>
|
|
|
</view>
|
|
|
- <view class="login_btn">立即兑换</view>
|
|
|
+ <view class="login_btn" @click="handleRedeem">立即兑换</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
@@ -66,13 +66,110 @@
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- selectedModule: 'douyin',
|
|
|
- globalImages: ''
|
|
|
+ selectedModule: 1,
|
|
|
+ globalImages: '',
|
|
|
+ exchangeCode: '', // 用于显示明文
|
|
|
+ encryptedCode: '',
|
|
|
+ isScanned: false // 是否是扫码
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
selectModule(module) {
|
|
|
this.selectedModule = module;
|
|
|
+ },
|
|
|
+
|
|
|
+ // 扫码逻辑(获取密文 -> 调用解密接口 -> 设置明文)
|
|
|
+ scanQRCode() {
|
|
|
+ uni.scanCode({
|
|
|
+ onlyFromCamera: false,
|
|
|
+ success: (res) => {
|
|
|
+ this.encryptedCode = res.result;
|
|
|
+ console.log('扫码密文:', this.encryptedCode);
|
|
|
+
|
|
|
+ if (!this.encryptedCode) {
|
|
|
+ return uni.showToast({ title: '扫码结果无效', icon: 'none' });
|
|
|
+ }
|
|
|
+
|
|
|
+ // this.isScanned = true; // 标记为扫码获取
|
|
|
+ uni.showLoading({ title: '解密中...' });
|
|
|
+
|
|
|
+ this.$Request.getT("/app/redeemCode/decryptAES?encryptedData=" + this.encryptedCode)
|
|
|
+ .then(res => {
|
|
|
+ uni.hideLoading();
|
|
|
+ if (res.code === 0 && res.data) {
|
|
|
+ this.exchangeCode = res.data; // 解密成功,赋值明文
|
|
|
+ this.isScanned = true;
|
|
|
+ } else {
|
|
|
+ this.exchangeCode = '';
|
|
|
+ this.isScanned = false;
|
|
|
+ uni.showToast({ title: res.msg || '解密失败', icon: 'none' });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ uni.hideLoading();
|
|
|
+ this.exchangeCode = '';
|
|
|
+ this.isScanned = false;
|
|
|
+ uni.showToast({ title: '解密接口异常', icon: 'none' });
|
|
|
+ console.error('解密错误:', err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ uni.showToast({ title: '扫码失败', icon: 'none' });
|
|
|
+ console.error('扫码失败:', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 点击“立即兑换”
|
|
|
+ handleRedeem() {
|
|
|
+ if (!this.exchangeCode) {
|
|
|
+ return uni.showToast({ title: '请输入兑换码', icon: 'none' });
|
|
|
+ }
|
|
|
+
|
|
|
+ uni.showLoading({ title: '兑换中...' });
|
|
|
+
|
|
|
+ // 如果是扫码(走解密流程后),调用正式兑换接口
|
|
|
+ if (this.isScanned) {
|
|
|
+ this.$Request.getT("/app/redeemCode/useRedeemCode?platform=" + this.selectedModule + '&encryptedData=' + this.encryptedCode)
|
|
|
+ .then(res => {
|
|
|
+ uni.hideLoading();
|
|
|
+ if (res.code === 0) {
|
|
|
+ uni.showToast({ title: '兑换成功', icon: 'success' });
|
|
|
+ this.resetFields();
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: res.msg || '兑换失败', icon: 'none' });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ uni.hideLoading();
|
|
|
+ uni.showToast({ title: '请求出错', icon: 'none' });
|
|
|
+ console.error('兑换失败:', err);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 手动输入走正常兑换
|
|
|
+ this.$Request.getT("/app/redeemCode/useRedeemCode?platform=" + this.selectedModule + '&cdk=' + this.exchangeCode)
|
|
|
+ .then(res => {
|
|
|
+ uni.hideLoading();
|
|
|
+ if (res.code === 0) {
|
|
|
+ uni.showToast({ title: '兑换成功', icon: 'success' });
|
|
|
+ this.resetFields();
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: res.msg || '兑换失败', icon: 'none' });
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ uni.hideLoading();
|
|
|
+ uni.showToast({ title: '请求出错', icon: 'none' });
|
|
|
+ console.error('兑换失败:', err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 重置表单
|
|
|
+ resetFields() {
|
|
|
+ this.exchangeCode = '';
|
|
|
+ this.encryptedCode = '';
|
|
|
+ this.isScanned = false;
|
|
|
}
|
|
|
},
|
|
|
onLoad() {
|