QrPayView.lua
5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local QrPayView = dialog.uinode("ui/QrPayLayer.csb",import(".BaseView"))
QrPayView.tabIndex = 1;
--支付宝微信二维码支付界面
function QrPayView:ctor()
QrPayView.super.ctor(self);
end
function QrPayView:show(params)
local scene = cc.Director:getInstance():getRunningScene()
local inst = QrPayView:create();
scene:addChild(inst, dialog.ZORDER_APP);
inst:setContentSize(cc.size(display.width,display.height));
ccui.Helper:doLayout(inst);
local panel = inst:getChildByName("panel");
panel:setScale(0.5);
local scaleTo = cc.ScaleTo:create(0.2,1);
panel:runAction(scaleTo);
inst.params = params;
inst:init();
inst.onPaySuccResFunHandler = handler(inst,inst.onPaySuccResFun);
cmsg.on("gateway_msg.notify_pay_succ_msg_res",inst.onPaySuccResFunHandler);
return inst;
end
function QrPayView:onPaySuccResFun(params)
local product = params.data.product;
cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler);
self:close();
end
function QrPayView:init()
self:getChildByName("panel"):getChildByName("txt_name"):setString("产品名称:"..self.params.subject);
self:getChildByName("panel"):getChildByName("txt_price"):setString("¥"..self.params.price);
self.qr = self:getChildByName("panel"):getChildByName("qr");
self.btn_alipay = self:getChildByName("panel"):getChildByName("btn_alipay");
self.btn_alipay.fn = handler(self,self.onAliPay);
self.btn_alipay:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, self.btn_alipay.fn)end);
self.btn_wx = self:getChildByName("panel"):getChildByName("btn_wx");
self.btn_wx.fn = handler(self,self.onWxPay);
self.btn_wx:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, self.btn_wx.fn)end);
local btn_close = self:getChildByName("panel"):getChildByName("btn_close");
btn_close.fn = handler(self,self.onCancel);
btn_close:addTouchEventListener(function(ref,type) self:onButtonClick(ref,type, btn_close.fn)end);
self.nodes[1] = {self.btn_alipay,self.btn_wx};
self.nodes[2] = {btn_close};
self.nodeIndex = 1;
self:updateSelectedState(false);
self.tabIndex = 1;
self:updateTab();
end
function QrPayView:onAliPay()
self.tabIndex = 1;
self:updateTab();
end
function QrPayView:onWxPay()
self.tabIndex = 2;
self:updateTab();
end
function QrPayView:updateTab()
for i,v in ipairs(self.nodes[1]) do
if i == self.tabIndex then
v:getChildByName("bg"):setVisible(true);
self:getChildByName("panel"):getChildByName("qr_"..i):setVisible(true);
else
v:getChildByName("bg"):setVisible(false);
self:getChildByName("panel"):getChildByName("qr_"..i):setVisible(false);
end
end
local qr_view = self:getChildByName("panel"):getChildByName("qr_"..self.tabIndex);
local function callBack(params)
if params.result == 0 then
local qr_url = params.url;
local NetImage = require("src.app.views.view.NetImage");
local img = NetImage:create(qr_url,250,250);
qr_view:removeAllChildren();
qr_view:addChild(img);
else
Alert.showOne(params.msg);
end
end
if not qr_view.isShow then
local trade_no = self.params.trade_no;
local subject = self.params.subject;
local total_amount = tonumber(self.params.price);
-- total_amount = 0.01;
if self.tabIndex == 1 then
local zfb_url = self.params.zfb_url;
local paramsStr = "out_trade_no="..trade_no.."&appid=1".."&subject="..subject.."&total_amount="..total_amount.."¬ify_url="..zfb_url;
MyHttpRequest:getInstance():request("POST",PAY_URL.."/alipay/getqr.php","",paramsStr,callBack);
else
local wx_url = self.params.wx_url;
local paramsStr = "out_trade_no="..trade_no.."&appid=1".."&subject="..subject.."&total_amount="..total_amount.."¬ify_url="..wx_url;
MyHttpRequest:getInstance():request("POST",PAY_URL.."/wxpay/getqr.php","",paramsStr,callBack);
end
qr_view.isShow = true;
end
end
function QrPayView:onCancel()
cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler);
self:close();
end
--返回键处理函数
function QrPayView:onKeypadBack()
cmsg.off("gateway_msg.notify_pay_succ_msg_res",self.onPaySuccResFunHandler);
self:close();
end
--左键处理函数
function QrPayView:onKeypadLeft(isBounce)
if self.selectedIndex > 1 then
QrPayView.super.onKeypadLeft(self,false);
end
local curNode = self.nodes[self.nodeIndex][self.selectedIndex];
if curNode:getName() == "btn_alipay" then
self:onAliPay();
elseif curNode:getName() == "btn_wx" then
self:onWxPay();
end
end
--左键处理函数
function QrPayView:onKeypadRight(isBounce)
if self.selectedIndex < #self.nodes then
QrPayView.super.onKeypadRight(self,false);
end
local curNode = self.nodes[self.nodeIndex][self.selectedIndex];
if curNode:getName() == "btn_alipay" then
self:onAliPay();
elseif curNode:getName() == "btn_wx" then
self:onWxPay();
end
end
return QrPayView