|
|
@@ -11,9 +11,10 @@ import '../model/UserInfo.dart';
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
|
|
class ChoosePay extends StatefulWidget {
|
|
|
- ChoosePay(this.type, this.chooseProduct);
|
|
|
+ ChoosePay(this.type, this.chooseProduct, this.payWay);
|
|
|
int type;
|
|
|
ProductInfo chooseProduct;
|
|
|
+ int payWay;
|
|
|
@override
|
|
|
_ChoosePayState createState() => _ChoosePayState();
|
|
|
}
|
|
|
@@ -54,7 +55,7 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- } else {}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
@@ -63,7 +64,16 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
// fluwx.register(appId: "wx62f8a9c1d3d70245");
|
|
|
Future.delayed(Duration.zero, () {
|
|
|
getUserInfo();
|
|
|
- getInfo();
|
|
|
+ if (widget.payWay == 1) {
|
|
|
+ getInfo();
|
|
|
+ } else {
|
|
|
+ print('aaaaaaa');
|
|
|
+ setState(() {
|
|
|
+ isWechat = true;
|
|
|
+ isAlipay = true;
|
|
|
+ chooseKey = 'wechat';
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -135,34 +145,48 @@ class _ChoosePayState extends State<ChoosePay> with WidgetsBindingObserver {
|
|
|
textColor: Colors.white,
|
|
|
child: Text('立即支付'),
|
|
|
onPressed: () async {
|
|
|
- int stockId = 0;
|
|
|
- Toast.show(context, '加载中', -1, 'loading');
|
|
|
-
|
|
|
- print(widget.chooseProduct.money);
|
|
|
- print(chooseKey);
|
|
|
-
|
|
|
- final Result res1 = await HttpManager.get('payCodeStock/randomStock', data: {'money': widget.chooseProduct.money, 'payType': chooseKey});
|
|
|
- print(res1.data);
|
|
|
- if (res1.success) {
|
|
|
- stockId = res1.data['id'];
|
|
|
- }
|
|
|
- else{
|
|
|
- Toast.hide();
|
|
|
- }
|
|
|
-
|
|
|
- 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 (widget.payWay == 2) {
|
|
|
+ String url = HttpManager.baseUrl +
|
|
|
+ '/apay/unifiedOrder?userId=' +
|
|
|
+ userId.toString() +
|
|
|
+ '&productId=' +
|
|
|
+ widget.chooseProduct.id.toString() +
|
|
|
+ '&bankcode=' +
|
|
|
+ (chooseKey == 'wechat' ? '901' : '904');
|
|
|
if (await canLaunch(url)) {
|
|
|
await launch(url);
|
|
|
} else {
|
|
|
throw 'Could not launch $url';
|
|
|
}
|
|
|
} else {
|
|
|
- Toast.show(context, res.error, 1500, 'info');
|
|
|
+ int stockId = 0;
|
|
|
+ Toast.show(context, '加载中', -1, 'loading');
|
|
|
+
|
|
|
+ print(widget.chooseProduct.money);
|
|
|
+ print(chooseKey);
|
|
|
+
|
|
|
+ final Result res1 = await HttpManager.get('payCodeStock/randomStock', data: {'money': widget.chooseProduct.money, 'payType': chooseKey});
|
|
|
+ print(res1.data);
|
|
|
+ if (res1.success) {
|
|
|
+ stockId = res1.data['id'];
|
|
|
+ } else {
|
|
|
+ Toast.hide();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ Toast.show(context, res.error, 1500, 'info');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// return;
|