Commit 9ca09b25 authored by liujiangnan's avatar liujiangnan

feat: 微信支付1

parent bf051129
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -8,13 +8,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
addPreloadImage() {
// TODO 根据自己的配置预加载图片资源
this._imageResList.push({ url: this.data.pic_url });
this._imageResList.push({ url: this.data.pic_url_2 });
}
addPreloadAudio() {
// TODO 根据自己的配置预加载音频资源
this._audioResList.push({ url: this.data.audio_url });
}
addPreloadAnima() {
......
import { delayCall } from "../../../form_angular/src/app/play/Unit";
import { initAir } from "./air";
import { middleLayerBase } from "./middleLayerBase";
import { asyncDelay, asyncLoadDragonBoneAnime, buttonOnceClick, buttonOnClick } from "./util";
import { asyncDelay, getSpriteFrimeByUrl, buttonOnceClick, buttonOnClick, guid } from "./util";
const { ccclass, property } = cc._decorator;
......@@ -116,6 +117,42 @@ export default class NewClass extends middleLayerBase {
cc.find(`middleLayer/iosActiveLayer/buyloading`).active = false;
cc.find(`middleLayer/iosActiveLayer/buy_status_win`).active = false;
}
async wxBuy (product) {
const statusWin = cc.find(`middleLayer/androidActiveLayer/buy_status_win`);
cc.find(`buy_result_text`, statusWin).getComponent(cc.Label).string = `请使用微信扫码二维码付款`;
// 生成二维码
let icon = cc.find(`qrcode`, statusWin).getComponent(cc.Sprite);
// 加载远程网络图片
const kidInfo = await this.getUserBaseInfo();
const userId = kidInfo.parent_id;
const productid = product.id;
const puid = userId;
const payuuid = guid();
const baseUrl = await this.getBaseUrl();
cc.loader.load({url: `${baseUrl}/api/wxpay/v1/oxfordlite/qrcode?productid=${productid}&puid=${puid}&payuuid=${payuuid}`, type: "png"}, (err, text) => {
icon.spriteFrame = new cc.SpriteFrame(text);
});
statusWin.active = true;
const queryPayStatus = async () => {
if (!statusWin.active) {
return;
}
const flag = await this.asyncCallNetworkApiGet(`/api/wxpay/v1/oxfordlite/checkorder`, {payuuid});
if (flag == 'true') {
cc.find(`buy_result_text`, statusWin).getComponent(cc.Label).string = `新获得:${product.name}探索时间${product.days}天`;
cc.find(`active_btn`, statusWin).active = true;
return;
}
setTimeout(() => {
queryPayStatus();
}, 500);
}
await queryPayStatus();
}
// 购买
async buy(product) {
// 苹果支付
......@@ -205,6 +242,35 @@ export default class NewClass extends middleLayerBase {
}
}
cc.find(`loading`, tipsLayer).active = false;
} else if (this.type != 'aixuebao') {
const tipsLayer = cc.find('middleLayer/androidActiveLayer');
cc.find(`loading`, tipsLayer).active = true;
tipsLayer.active = true;
const token = cc.sys.localStorage.getItem('token');
const res: any = await this.asyncCallNetworkApiGet('/api/oxford/v1/product/list', {token});
const products = JSON.parse(res).rows;
let index = 1;
for (let i = 0; i < products.length; i++) {
const pd = products[i];
if (pd.type_ == 1) {
cc.find(`active_bg/1_5_product/card/buy`, tipsLayer).attr({ product: pd });
} else {
const cardNode = cc.find(`active_bg/one_level_product`, tipsLayer);
const levelNode = cc.find(`level${index}`, cardNode);
cc.find(`buy`, levelNode).attr({ product: pd });
const endDate = pd.syll_end_date;
if (endDate) {
cc.find(`buy/text`, levelNode).getComponent(cc.Label).string = "续费";
cc.find(`tips`, levelNode).getComponent(cc.Label).string = `有效期至 ${endDate.split("T")[0].trim()}`;
cc.find(`tips`, levelNode).active = true;
} else {
cc.find(`buy/text`, levelNode).getComponent(cc.Label).string = "立即购买";
cc.find(`tips`, levelNode).active = false;
}
index++;
}
}
cc.find(`loading`, tipsLayer).active = false;
} else {
const tipsLayer = cc.find('middleLayer/activeLayer');
tipsLayer.active = true;
......@@ -776,6 +842,7 @@ export default class NewClass extends middleLayerBase {
this.loadOnlineBundle('NJ_login');
}
this.initListener();
}
onClickExitBtn() {
......@@ -838,54 +905,7 @@ export default class NewClass extends middleLayerBase {
});
}
initListener() {
const exitBtn = cc.find('middleLayer/ExitBtn');
buttonOnClick(exitBtn, () => {
this.onClickExitBtn();
});
buttonOnClick(cc.find('middleLayer/BtnRight'), () => {
if (this.courseIndex === this.courses.length - 1) {
// 说明是最后一页
this.showTips("已经是最后一页了~");
return;
}
// this.showConfirm("确定跳过吗?", () => {
if (!this.isShowWaiting) {
this.goNextPage();
}
// });
});
buttonOnClick(cc.find('middleLayer/BtnLeft'), () => {
this.goPrePage();
});
buttonOnClick(cc.find('middleLayer/activeLayer/close'), () => {
cc.find('middleLayer/activeLayer').active = false;
});
buttonOnClick(cc.find('middleLayer/activeLayer/active_bg/active'), async () => {
const input = cc.find('middleLayer/activeLayer/active_bg/active_input').getComponent(cc.EditBox);
const activeCode = input.textLabel.string;
const kidInfo = await this.getUserInfo();
if (!kidInfo) {
return;
}
const res = await this.asyncCallNetworkApiPost(`/api/oxford/v1/user/bind`, {
kid_id: kidInfo.id, book_code: activeCode, token: cc.sys.localStorage.getItem('token')
});
if (res && res.code == 200) {
this.showTips(res.msg);
cc.find('middleLayer/activeLayer').active = false;
input.textLabel.string = "";
await this.getUserInfo();
this.reloadBundle();
} else {
this.showTips(res.msg);
}
});
initIosActiveWinListener() {
// IOS 激活窗口事件绑定
const iosActiveWin = cc.find('middleLayer/iosActiveLayer');
buttonOnClick(cc.find('close', iosActiveWin), () => {
......@@ -975,6 +995,147 @@ export default class NewClass extends middleLayerBase {
this.loadOnlineBundle('NJ_YouLeChang');
});
}
initAndroidActiveWinListener() {
// 安卓激活窗口事件绑定
const androidActiveWin = cc.find('middleLayer/androidActiveLayer');
buttonOnClick(cc.find('close', androidActiveWin), () => {
cc.find('buy_status_win/active_btn', androidActiveWin).active = false;
cc.find(`buy_status_win`, androidActiveWin).active = false;
androidActiveWin.active = false;
this.loadOnlineBundle('NJ_YouLeChang');
});
buttonOnClick(cc.find('active_bg/input_book_code/active', androidActiveWin), async () => {
const input = cc.find('active_bg/input_book_code/active_input', androidActiveWin).getComponent(cc.EditBox);
const activeCode = input.textLabel.string;
const kidInfo = await this.getUserInfo();
if (!kidInfo) {
return;
}
const res = await this.asyncCallNetworkApiPost(`/api/oxford/v1/user/bind`, {
kid_id: kidInfo.id, book_code: activeCode, token: cc.sys.localStorage.getItem('token')
});
if (res && res.code == 200) {
this.showTips(res.msg);
androidActiveWin.active = false;
input.textLabel.string = "";
await this.getUserInfo();
this.reloadBundle();
} else {
this.showTips(res.msg);
}
});
buttonOnClick(cc.find('active_bg/buy1_5', androidActiveWin), () => {
cc.find('active_bg/1_5_product', androidActiveWin).active = true;
cc.find('active_bg/one_level_product', androidActiveWin).active = false;
cc.find('active_bg/input_book_code', androidActiveWin).active = false;
cc.find('active_bg/buy1_5/xb_active', androidActiveWin).active = true;
cc.find('active_bg/buy_one/xb_active', androidActiveWin).active = false;
cc.find('active_bg/buy_book_code/xb_active', androidActiveWin).active = false;
});
buttonOnClick(cc.find('active_bg/buy_one', androidActiveWin), () => {
cc.find('active_bg/1_5_product', androidActiveWin).active = false;
cc.find('active_bg/one_level_product', androidActiveWin).active = true;
cc.find('active_bg/input_book_code', androidActiveWin).active = false;
cc.find('active_bg/buy1_5/xb_active', androidActiveWin).active = false;
cc.find('active_bg/buy_one/xb_active', androidActiveWin).active = true;
cc.find('active_bg/buy_book_code/xb_active', androidActiveWin).active = false;
});
buttonOnClick(cc.find('active_bg/buy_book_code', androidActiveWin), () => {
cc.find('active_bg/1_5_product', androidActiveWin).active = false;
cc.find('active_bg/one_level_product', androidActiveWin).active = false;
cc.find('active_bg/input_book_code', androidActiveWin).active = true;
cc.find('active_bg/buy1_5/xb_active', androidActiveWin).active = false;
cc.find('active_bg/buy_one/xb_active', androidActiveWin).active = false;
cc.find('active_bg/buy_book_code/xb_active', androidActiveWin).active = true;
});
buttonOnClick(cc.find('active_bg/1_5_product/card/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level1/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level2/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level3/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level4/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level5/buy', androidActiveWin), (btn) => {
this.wxBuy(btn.product);
});
buttonOnClick(cc.find('buy_status_win/active_btn', androidActiveWin), (btn) => {
btn.active = false;
cc.find(`buy_status_win`, androidActiveWin).active = false;
androidActiveWin.active = false;
this.loadOnlineBundle('NJ_YouLeChang');
});
}
initListener() {
const exitBtn = cc.find('middleLayer/ExitBtn');
buttonOnClick(exitBtn, () => {
this.onClickExitBtn();
});
buttonOnClick(cc.find('middleLayer/BtnRight'), () => {
if (this.courseIndex === this.courses.length - 1) {
// 说明是最后一页
this.showTips("已经是最后一页了~");
return;
}
// this.showConfirm("确定跳过吗?", () => {
if (!this.isShowWaiting) {
this.goNextPage();
}
// });
});
buttonOnClick(cc.find('middleLayer/BtnLeft'), () => {
this.goPrePage();
});
buttonOnClick(cc.find('middleLayer/activeLayer/close'), () => {
cc.find('middleLayer/activeLayer').active = false;
});
buttonOnClick(cc.find('middleLayer/activeLayer/active_bg/active'), async () => {
const input = cc.find('middleLayer/activeLayer/active_bg/active_input').getComponent(cc.EditBox);
const activeCode = input.textLabel.string;
const kidInfo = await this.getUserInfo();
if (!kidInfo) {
return;
}
const res = await this.asyncCallNetworkApiPost(`/api/oxford/v1/user/bind`, {
kid_id: kidInfo.id, book_code: activeCode, token: cc.sys.localStorage.getItem('token')
});
if (res && res.code == 200) {
this.showTips(res.msg);
cc.find('middleLayer/activeLayer').active = false;
input.textLabel.string = "";
await this.getUserInfo();
this.reloadBundle();
} else {
this.showTips(res.msg);
}
});
this.initIosActiveWinListener();
this.initAndroidActiveWinListener();
buttonOnClick(cc.find(`middleLayer/exception_pay_win/active_btn`), (btn) => {
cc.find(`middleLayer/exception_pay_win`).active = false;
......
......@@ -85,17 +85,19 @@ export abstract class middleLayerBase extends cc.Component {
ORG_ID;
DOMAIN;
async getBaseUrl(callback) {
async getBaseUrl(callback = null) {
const engineInfo = await this.getEngineInfo();
const { isDev } = JSON.parse(engineInfo);
if (isDev == 1) {
this.ORG_ID = 513;
this.DOMAIN = "http://staging-teach.cdn.ireadabc.com/";
callback('http://staging-openapi.iteachabc.com');
callback && callback('http://staging-openapi.iteachabc.com');
return 'http://staging-openapi.iteachabc.com';
} else {
this.ORG_ID = 512;
this.DOMAIN = "http://teach.cdn.ireadabc.com/";
callback('http://openapi.iteachabc.com');
callback && callback('http://openapi.iteachabc.com');
return 'http://openapi.iteachabc.com';
}
}
......
......@@ -538,3 +538,11 @@ export function buttonOnClick(button: cc.Node, callback: Function, scale = 1.0)
.start();
});
}
export function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment