Commit 51e6f98e authored by liujiangnan's avatar liujiangnan

feat: 版本切面,IOS支付功能

parent 2db66ac2
......@@ -34,6 +34,7 @@ export function initAir(_this) {
takePictureCallBack: null,
configurationPortraitCallback: null,
configurationLandscapeCallback: null,
startBuyToAppStoreCallBack: null,
recognitionCameraCallBack: null,
testCallBack: null,
recordCallBack: null,
......@@ -290,6 +291,14 @@ export function initAir(_this) {
};
window.courseware.callOcMethod("onConfigurationLandscape", params);
},
startBuyToAppStore(params = {}, callback) {
// 苹果支付
_this.log(`===成功调用startBuyToAppStore===`);
window.air.startBuyToAppStoreCallBack = (res) => {
callback && callback(res);
};
window.courseware.callOcMethod("startBuyToAppStore", params);
},
callOcMethod(method, param) {
const paramStr = JSON.stringify(param);
_this.log(`===成功调用原生方法${method}===参数==${paramStr}`);
......@@ -309,6 +318,8 @@ export function initAir(_this) {
} else if (method == 'startRecord') {
} else if (method == 'stopRecord') {
window.air.recordCallBack(recordMockData);
} else if (method == 'startBuyToAppStore') {
window.air.startBuyToAppStoreCallBack({productid: 1, puid: 22, receiptData: "HelloWorld"});
} else{
console.error(`${method}方法还没有Mock数据,请联系技术支持人员添加`);
}
......
......@@ -111,12 +111,92 @@ export default class NewClass extends middleLayerBase {
tipsLayer.active = false;
});
}
hideBuyLoading() {
cc.find(`middleLayer/iosActiveLayer/buyloading`).active = false;
cc.find(`middleLayer/iosActiveLayer/buy_status_win`).active = false;
}
// 购买
async buy(product) {
// 苹果支付
cc.find(`middleLayer/iosActiveLayer/buyloading`).active = true;
const statusWin = cc.find(`middleLayer/iosActiveLayer/buy_status_win`);
statusWin.active = true;
const kidInfo = await this.getUserBaseInfo();
const userId = kidInfo.parent_id;
cc.find(`buy_status_text`, statusWin).getComponent(cc.Label).string = "支付中,请勿关闭App";
(<any>window).courseware.startBuyToAppStore({
productid: product.id,
puid: userId,
ios_product_str: product.ios_product_str
}, async (res) => {
if (typeof (res) == 'string') {
res = JSON.parse(res);
}
const orderData:any = await this.asyncCallNetworkApiPost(`/api/oxford/v1/paid/ios/order/save`, {
productid: res.productid,
puid: res.puid,
iospaidcode: res.receiptData
});
if (orderData.code!=200) {
cc.find(`buy_status_text`, statusWin).getComponent(cc.Label).string = `支付失败[${orderData.code}]`;
cc.find(`buy_status_sub_text`, statusWin).getComponent(cc.Label).string = `请联系客服`;
cc.find(`buy_status_sub_text`, statusWin).active = true;
return;
}
cc.find(`buy_status_text`, statusWin).getComponent(cc.Label).string = `购买成功!`;
cc.find(`buy_status_sub_text`, statusWin).getComponent(cc.Label).string = `快去探索绘玩绘拼自然拼读世界吧!`;
cc.find(`buy_status_sub_text`, statusWin).active = true;
cc.find(`buy_result_text`, statusWin).getComponent(cc.Label).string = `新获得:${product.name}探索时间${product.days}天`;
cc.find(`buy_result_text`, statusWin).active = true;
cc.find(`active_btn`, statusWin).active = true;
})
}
async showActiveWindow() {
if (this.IS_BUNDLE_LOADING) {
return;
}
const tipsLayer = cc.find('middleLayer/activeLayer');
tipsLayer.active = true;
// if (cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS) {
if (true) {
const tipsLayer = cc.find('middleLayer/iosActiveLayer');
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/label`, tipsLayer).getComponent(cc.Label).string = pd.name;
cc.find(`active_bg/1_5_product/card/price`, tipsLayer).getComponent(cc.Label).string = pd.price;
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(`label`, levelNode).getComponent(cc.Label).string = pd.name;
cc.find(`price`, levelNode).getComponent(cc.Label).string = pd.price;
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()}`;
} else {
cc.find(`buy/text`, levelNode).getComponent(cc.Label).string = "购买";
cc.find(`tips`, levelNode).getComponent(cc.Label).string = "未购买";
}
index++;
}
}
cc.find(`loading`, tipsLayer).active = false;
} else {
const tipsLayer = cc.find('middleLayer/activeLayer');
tipsLayer.active = true;
}
}
version = null;
......@@ -636,10 +716,20 @@ export default class NewClass extends middleLayerBase {
cc.sys.localStorage.setItem('token', token);
}
// 处理苹果支付的异常回调
(<any>window).air.startBuyToAppStoreCallBack = async (res) => {
if (typeof (res) == 'string') {
res = JSON.parse(res);
}
await this.asyncCallNetworkApiPost(`/v1/paid/ios/order/save`, {
productid: res.productid,
puid: res.puid,
iospaidcode: res.receiptData
});
}
this.showWaitingLetters();
this.onMiddleLayerLoadingFinish();
const token = cc.sys.localStorage.getItem('token');
const kidDataStr = await this.asyncCallNetworkApiGet('/api/oxford/v1/kid/info', {
token: token
......@@ -762,6 +852,88 @@ export default class NewClass extends middleLayerBase {
}
});
// IOS 激活窗口事件绑定
const iosActiveWin = cc.find('middleLayer/iosActiveLayer');
buttonOnClick(cc.find('close', iosActiveWin), () => {
iosActiveWin.active = false;
});
buttonOnClick(cc.find('active_bg/input_book_code/active', iosActiveWin), async () => {
const input = cc.find('active_bg/input_book_code/active_input', iosActiveWin).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);
iosActiveWin.active = false;
input.textLabel.string = "";
await this.getUserInfo();
this.reloadBundle();
} else {
this.showTips(res.msg);
}
});
buttonOnClick(cc.find('active_bg/buy1_5', iosActiveWin), () => {
cc.find('active_bg/1_5_product', iosActiveWin).active = true;
cc.find('active_bg/one_level_product', iosActiveWin).active = false;
cc.find('active_bg/input_book_code', iosActiveWin).active = false;
});
buttonOnClick(cc.find('active_bg/buy_one', iosActiveWin), () => {
cc.find('active_bg/1_5_product', iosActiveWin).active = false;
cc.find('active_bg/one_level_product', iosActiveWin).active = true;
cc.find('active_bg/input_book_code', iosActiveWin).active = false;
});
buttonOnClick(cc.find('active_bg/buy_book_code', iosActiveWin), () => {
cc.find('active_bg/1_5_product', iosActiveWin).active = false;
cc.find('active_bg/one_level_product', iosActiveWin).active = false;
cc.find('active_bg/input_book_code', iosActiveWin).active = true;
});
buttonOnClick(cc.find('active_bg/1_5_product/card/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level1/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level2/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level3/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level4/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('active_bg/one_level_product/level5/buy', iosActiveWin), (btn) => {
this.buy(btn.product);
});
buttonOnClick(cc.find('buy_status_win/active_btn', iosActiveWin), (btn) => {
cc.find(`buy_status_win/buy_status_text`, iosActiveWin).getComponent(cc.Label).string = "";
cc.find(`buy_status_win/buy_status_sub_text`, iosActiveWin).getComponent(cc.Label).string = "";
cc.find(`buy_status_win/buy_status_sub_text`, iosActiveWin).active = false;
cc.find(`buy_status_win/buy_result_text`, iosActiveWin).active = false;
btn.active = false;
cc.find(`buy_status_win`, iosActiveWin).active = false;
cc.find(`buyloading`, iosActiveWin).active = false;
iosActiveWin.active = false;
this.loadOnlineBundle('NJ_YouLeChang');
});
};
playLocalAudio(audioName) {
......
......@@ -532,7 +532,7 @@ export function buttonOnClick(button: cc.Node, callback: Function, scale = 1.0)
.to(0.1, { scale: scale * 1.1 })
.to(0.1, { scale: scale })
.call(() => {
callback && callback();
callback && callback(button);
button['cantClick'] = false;
})
.start();
......
{
"ver": "2.3.5",
"uuid": "57d6176e-9dea-43a8-b2e0-c7691cf7d677",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 32,
"height": 32,
"platformSettings": {},
"subMetas": {
"mi": {
"ver": "1.0.4",
"uuid": "6cc989ef-5980-4fcb-a791-c5744ae155d5",
"rawTextureUuid": "57d6176e-9dea-43a8-b2e0-c7691cf7d677",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 1,
"offsetY": 0,
"trimX": 6,
"trimY": 2,
"width": 22,
"height": 28,
"rawWidth": 32,
"rawHeight": 32,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ 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