基础库
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

255 líneas
9.8 KiB

  1. import 'package:dio/dio.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_alibc/flutter_alibc.dart';
  4. import 'package:jdsdk/jdsdk.dart';
  5. import 'package:url_launcher/url_launcher.dart';
  6. import 'package:zhiying_comm/register.dart';
  7. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'package:zhiying_comm/pages/login_page/login_page.dart';
  10. import 'taobao_image_viewer.dart';
  11. void main() => runApp(MyApp());
  12. class MyApp extends StatefulWidget {
  13. @override
  14. _MyAppState createState() => _MyAppState();
  15. }
  16. class _MyAppState extends State<MyApp> {
  17. @override
  18. void initState() {
  19. BaseWidgetRegister.init();
  20. Jdsdk.init(appKey: '9fc3dec00b9b40cc950dfba5262cd6d3', appSecret: 'f785613e5fd54a129d0f0359a4e25c23').then((result) {
  21. Logger.debug('京东初始化:${result.toString()}');
  22. });
  23. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  24. Logger.debug('${result.errorCode} ${result.errorMessage}');
  25. });
  26. super.initState();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return MaterialApp(
  31. home: HomePage(),
  32. );
  33. }
  34. }
  35. class HomePage extends StatelessWidget {
  36. netPost() async {
  37. dynamic result = await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  38. print("result === ${result?.toString()}");
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Scaffold(
  43. appBar: AppBar(
  44. title: const Text('智莺-基础库'),
  45. ),
  46. body: SingleChildScrollView(
  47. child: Center(
  48. child: Wrap(
  49. spacing: 10,
  50. children: <Widget>[
  51. RaisedButton(
  52. onPressed: () {
  53. // d75d2fc6592f4526e297643446416581bd89e837
  54. // cc455e0c0b6a75ff09aeb966c211fb967d69b63d
  55. SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, 'd75d2fc6592f4526e297643446416581bd89e837');
  56. },
  57. child: Text('登录'),
  58. ),
  59. RaisedButton(
  60. onPressed: () {
  61. SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, '');
  62. },
  63. child: Text('退出登录'),
  64. ),
  65. RaisedButton(
  66. onPressed: () {
  67. NetUtil.request('/api/v1/rec/featured?page=1', params: null, onError: (msg) {
  68. print('onERROR = ${msg?.toString() ?? 'onError'}');
  69. }, onSuccess: (json) {
  70. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  71. }, onCache: (json) {
  72. print('onCache = ${json?.toString() ?? 'onCache'}');
  73. });
  74. },
  75. child: Text('网络异步请求(带缓存)'),
  76. ),
  77. RaisedButton(
  78. onPressed: () {
  79. netPost();
  80. },
  81. child: Text('网络同步请求(无缓存)'),
  82. ),
  83. RaisedButton(
  84. onPressed: () {
  85. // LogUtil.test();
  86. },
  87. child: Text('显示日志'),
  88. ),
  89. RaisedButton(
  90. onPressed: () {
  91. Navigator.push(context, MaterialPageRoute(builder: (_) {
  92. return Logger();
  93. }));
  94. },
  95. child: Text('打开日志视图'),
  96. ),
  97. RaisedButton(
  98. onPressed: () {
  99. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  100. // onSuccess: (params){
  101. // Logger.log("onSuccess#$params");
  102. // },
  103. // onCache: (params){
  104. // Logger.log("onCache#$params");
  105. // });
  106. testPost();
  107. },
  108. child: Text('测试接口'),
  109. ),
  110. RaisedButton(
  111. onPressed: () {
  112. Navigator.push(context, MaterialPageRoute(builder: (_) {
  113. return TaobaoImageView();
  114. }));
  115. },
  116. child: Text('抓淘宝图片'),
  117. ),
  118. RaisedButton(
  119. onPressed: () {
  120. TaobaoAuth.auth(context);
  121. },
  122. child: Text('淘宝授权'),
  123. ),
  124. RaisedButton(
  125. onPressed: () {
  126. //
  127. Dio dio = Dio();
  128. dio
  129. .get(
  130. 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html')
  131. .then((value) {
  132. Logger.debug(value.realUri.toString());
  133. });
  134. },
  135. child: Text('获取重定向地址'),
  136. ),
  137. RaisedButton(
  138. onPressed: () {
  139. Jdsdk.openUrl(
  140. url:
  141. 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html');
  142. },
  143. child: Text('打开京东详情'),
  144. ),
  145. RaisedButton(
  146. onPressed: () async {
  147. // String detailUrl = 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html';
  148. // String baseUrl = detailUrl.getBaseUrl();
  149. // if (!baseUrl.contains('jd.com')) {
  150. // Dio dio = Dio();
  151. // var responds = await dio.get(detailUrl);
  152. // detailUrl = responds.realUri.toString();
  153. // }
  154. // Logger.debug(detailUrl);
  155. // Jdsdk.openUrl(
  156. // url
  157. // :
  158. // detailUrl
  159. // );
  160. },
  161. child: Text('嗨如意转链打开京东'),
  162. ),
  163. RaisedButton(
  164. onPressed: () async {
  165. const url = 'weixin://';
  166. if (await canLaunch(url)) {
  167. await launch(url);
  168. } else {
  169. throw 'Could not launch $url';
  170. }
  171. },
  172. child: Text('url scheme打开app'),
  173. ),
  174. RaisedButton(
  175. onPressed: () async {
  176. Logger.error('打印日志测试');
  177. },
  178. child: Text('打印日志'),
  179. ),
  180. RaisedButton(
  181. onPressed: () async {
  182. List<PreviewImageData> previewImageDatas = List();
  183. for (var index = 0; index < 5; index++) {
  184. previewImageDatas.add(PreviewImageData(
  185. previewImageType: PreviewImageType.netUrl,
  186. data:
  187. "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604924972652&di=2849a989df574db3fbb7a8994ea87fc3&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fc%2F574420055d0b9.jpg"));
  188. }
  189. PhotoPreview.showPhotoPreview(context, previewImageDatas, currentIndex: 0);
  190. },
  191. child: Text('预览图片'),
  192. ),
  193. RaisedButton(
  194. onPressed: () async {
  195. Navigator.push(context, MaterialPageRoute(builder: (_) {
  196. return LoginPage();
  197. }));
  198. },
  199. child: Text('打开登录'),
  200. ),
  201. RaisedButton(
  202. onPressed: () async {
  203. toPay();
  204. },
  205. child: Text('支付宝支付'),
  206. ),
  207. ],
  208. ),
  209. ),
  210. ),
  211. );
  212. }
  213. void testPost() async {
  214. var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {
  215. 'ids': [7]
  216. });
  217. print("cahced ${cached?.toString()}");
  218. var param = await NetUtil.post('/api/v1/mod',
  219. params: {
  220. 'ids': [7]
  221. },
  222. method: NetMethod.POST);
  223. print('apapapsdjfdsjf: ${param?.toString()}');
  224. }
  225. ///支付宝支付
  226. void toPay() async {
  227. var result = await AliPayUtil.toPay('app_id=2016120103683451\u0026biz_content=%7B%22out_trade_no%22%3A%22706160993071863177%22%2C%22passback_params%22%3A%22706160993071863177%22%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%22%2C%22total_amount%22%3A%220.01%22%7D\u0026charset=utf-8\u0026format=JSON\u0026method=alipay.trade.app.pay\u0026notify_url=inapi.izhyin.cn%2Fapi%2Fv1%2Falipay%2Fcallback%3Fmaster_id%3D123456\u0026sign=juCL4eFWKDdpis0EEb8AHgazPql1QXODJ4K%2BglffzxkdUKhuPXBzkI4Fcull3RZ94kD63qlXAhGnbcPIYiUnxoec1sR5xEvEk3rxFJcmEBhPXMIX6nyh8Z2IdzeRzEjypidPR3U5T6OgdabaXADKjGd%2BKDH%2FhzCRSOyMf7TNazyoKAWX3D10R4QQjChDrBLXY6WTqrEcJVZVg8IgC1znZPuG3pO%2BtPFpiwjbT0rAcxWqj5ZbwddyDpfSM7gvpmBymDDvW3bUUQ8h4wszTClyvCQ6fXSeHX%2BgsFhqhkK01U4OhzDH4ipsMTe1Jz6fJveCICtdGd4c6Sikk%2Bhzn8br1w%3D%3D\u0026sign_type=RSA2\u0026timestamp=2021-01-06+18%3A58%3A38\u0026version=1.0');
  228. // var params = {'subject': '测试', 'amount': "0.01"};
  229. // print("请求数据");
  230. // NetUtil.request("/api/v1/user/alipay", params: params, method: NetMethod.POST, onSuccess: (data) async {
  231. // print(data);
  232. // var result = await AliPayUtil.toPay(data);
  233. // if(result){
  234. // print("支付成功");
  235. // }
  236. // },onError: (err){
  237. // print(err);
  238. // });
  239. }
  240. }