|
|
@@ -19,12 +19,41 @@ class ChoosePay extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
- String chooseKey = 'alipay';
|
|
|
+ String chooseKey = '';
|
|
|
+ bool isAlipay = false;
|
|
|
+ bool isWechat = false;
|
|
|
+ bool isCloud_flash = false;
|
|
|
+ bool isUnion_pay = false;
|
|
|
+ int userId = 0;
|
|
|
Future<void> getUserInfo() async {
|
|
|
Result res = await HttpManager.get('userInfo/getUserInfo');
|
|
|
if (res.success) {
|
|
|
print(res.data);
|
|
|
StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
|
|
|
+ userId = res.data['id'];
|
|
|
+ } else {}
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> getInfo() async {
|
|
|
+ Result res = await HttpManager.get('payCodeStock/allUsedPayType?moeny=${widget.chooseProduct.money}');
|
|
|
+ if (res.success) {
|
|
|
+ for (var item in res.data) {
|
|
|
+ setState(() {
|
|
|
+ if (item['payType'] == 'wechat') {
|
|
|
+ isWechat = true;
|
|
|
+ } else if (item['payType'] == 'alipay') {
|
|
|
+ isAlipay = true;
|
|
|
+ } else if (item['payType'] == 'cloud_flash') {
|
|
|
+ isCloud_flash = true;
|
|
|
+ } else if (item['payType'] == 'union_pay') {
|
|
|
+ isUnion_pay = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chooseKey == '') {
|
|
|
+ chooseKey = item['payType'];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {}
|
|
|
}
|
|
|
|
|
|
@@ -32,7 +61,10 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
// fluwx.register(appId: "wx62f8a9c1d3d70245");
|
|
|
- Future.delayed(Duration.zero, () => getUserInfo());
|
|
|
+ Future.delayed(Duration.zero, () {
|
|
|
+ getUserInfo();
|
|
|
+ getInfo();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -63,16 +95,34 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
- PayContent('支付宝', '支持有支付宝,网银的用户使用', 'images/icon_zhifubao.png', 'alipay', chooseKey, () {
|
|
|
- setState(() {
|
|
|
- chooseKey = 'alipay';
|
|
|
- });
|
|
|
- }),
|
|
|
- PayContent('微信支付', '使用微信支付,方便快捷', 'images/icon_weixin.png', 'wxpay', chooseKey, () {
|
|
|
- setState(() {
|
|
|
- chooseKey = 'wxpay';
|
|
|
- });
|
|
|
- })
|
|
|
+ isAlipay
|
|
|
+ ? PayContent('支付宝', '支持有支付宝,网银的用户使用', 'images/icon_zhifubao.png', 'alipay', chooseKey, () {
|
|
|
+ setState(() {
|
|
|
+ chooseKey = 'alipay';
|
|
|
+ });
|
|
|
+ })
|
|
|
+ : Container(),
|
|
|
+ isWechat
|
|
|
+ ? PayContent('微信支付', '使用微信支付,方便快捷', 'images/icon_weixin.png', 'wechat', chooseKey, () {
|
|
|
+ setState(() {
|
|
|
+ chooseKey = 'wechat';
|
|
|
+ });
|
|
|
+ })
|
|
|
+ : Container(),
|
|
|
+ isCloud_flash
|
|
|
+ ? PayContent('云闪付', '支持各大银联银行支付', 'images/pay1.png', 'wechat', chooseKey, () {
|
|
|
+ setState(() {
|
|
|
+ chooseKey = 'wechat';
|
|
|
+ });
|
|
|
+ })
|
|
|
+ : Container(),
|
|
|
+ isUnion_pay
|
|
|
+ ? PayContent('银联支付', '支持各大银联银行支付', 'images/pay1.png', 'wechat', chooseKey, () {
|
|
|
+ setState(() {
|
|
|
+ chooseKey = 'wechat';
|
|
|
+ });
|
|
|
+ })
|
|
|
+ : Container()
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
@@ -85,12 +135,29 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
textColor: Colors.white,
|
|
|
child: Text('立即支付'),
|
|
|
onPressed: () async {
|
|
|
- const url = 'https://flutter.dev';
|
|
|
- if (await canLaunch(url)) {
|
|
|
- await launch(url);
|
|
|
+ int stockId = 0;
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+
|
|
|
+ final Result res1 = await HttpManager.get('payCodeStock/randomStock', data: {'money': widget.chooseProduct.money, 'payType': chooseKey});
|
|
|
+ if (res1.success) {
|
|
|
+ stockId = res1.data['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ final Result res =
|
|
|
+ await HttpManager.post('payCodeOrder/submit', data: {'userId': userId, 'stockId': stockId, 'productId': widget.chooseProduct.id});
|
|
|
+ Toast.hide();
|
|
|
+
|
|
|
+ if (res.success) {
|
|
|
+ String url = HttpManager.baseUrl + 'phone/#/pay?id=${res.data}';
|
|
|
+ if (await canLaunch(url)) {
|
|
|
+ await launch(url);
|
|
|
+ } else {
|
|
|
+ throw 'Could not launch $url';
|
|
|
+ }
|
|
|
} else {
|
|
|
- throw 'Could not launch $url';
|
|
|
+ Toast.show(context, res.error, 1500, 'info');
|
|
|
}
|
|
|
+
|
|
|
// return;
|
|
|
// String ipAddress = await GetIp.ipAddress;
|
|
|
// print(ipAddress);
|
|
|
@@ -106,7 +173,7 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
// print(res);
|
|
|
// });
|
|
|
// MyDialog.showDialog(context, '已经成功调起微信支付', submitText: '支付完成', isCancel: true, onsubmit: () async {
|
|
|
- // final Result res2 = await HttpManager.get('wxpayTemp/getWxpayTemp', data: {'id': res.data["id"]});
|
|
|
+ // final Result res2 = await HttpManager.get('wechatTemp/getwechatTemp', data: {'id': res.data["id"]});
|
|
|
// if (res2.success && res2.data != new Map()) {
|
|
|
// if (res2.data['resultCode'] == 'NOT_PAY') {
|
|
|
// Toast.show(context, '支付取消', 1500, 'info');
|