基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

215 lines
7.4 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/pages/launch_page/launch_page.dart';
  7. import 'package:zhiying_comm/register.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'taobao_image_viewer.dart';
  10. void main() => runApp(MyApp());
  11. class MyApp extends StatefulWidget {
  12. @override
  13. _MyAppState createState() => _MyAppState();
  14. }
  15. class _MyAppState extends State<MyApp> {
  16. @override
  17. void initState() {
  18. BaseWidgetRegister.init();
  19. Jdsdk.init(
  20. appKey: '9fc3dec00b9b40cc950dfba5262cd6d3',
  21. appSecret: 'f785613e5fd54a129d0f0359a4e25c23')
  22. .then((result) {
  23. Logger.debug('京东初始化:${result.toString()}');
  24. });
  25. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  26. Logger.debug('${result.errorCode} ${result.errorMessage}');
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return MaterialApp(home: LaunchPage(builder: (context) => HomePage(),),);
  33. }
  34. }
  35. class HomePage extends StatelessWidget {
  36. netPost() async {
  37. dynamic result =
  38. await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  39. print("result === ${result?.toString()}");
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return Scaffold(
  44. appBar: AppBar(
  45. title: const Text('智莺-基础库'),
  46. ),
  47. body: SingleChildScrollView(
  48. child: Center(
  49. child: Wrap(
  50. spacing: 10,
  51. children: <Widget>[
  52. RaisedButton(
  53. onPressed: () {
  54. Navigator.push(context, MaterialPageRoute(builder: (_) {
  55. // return DeviceInfoPage();
  56. }));
  57. },
  58. child: Text('设备信息'),
  59. ),
  60. RaisedButton(
  61. onPressed: () {
  62. Navigator.push(context, MaterialPageRoute(builder: (_) {
  63. // return PackageInfoPage();
  64. }));
  65. },
  66. child: Text('应用信息'),
  67. ),
  68. RaisedButton(
  69. onPressed: () {
  70. NetUtil.post('/siteapi/v1/ucenter/login/', params: {
  71. 'username': 'xiangguohui',
  72. 'password': 'fnuo123com'
  73. });
  74. },
  75. child: Text('登录请求'),
  76. ),
  77. RaisedButton(
  78. onPressed: () {
  79. NetUtil.request('/api/v1/rec/featured?page=1', params: null,
  80. onError: (msg) {
  81. print('onERROR = ${msg?.toString() ?? 'onError'}');
  82. }, onSuccess: (json) {
  83. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  84. }, onCache: (json) {
  85. print('onCache = ${json?.toString() ?? 'onCache'}');
  86. });
  87. },
  88. child: Text('网络异步请求(带缓存)'),
  89. ),
  90. RaisedButton(
  91. onPressed: () {
  92. netPost();
  93. },
  94. child: Text('网络同步请求(无缓存)'),
  95. ),
  96. RaisedButton(
  97. onPressed: () {
  98. // LogUtil.test();
  99. },
  100. child: Text('显示日志'),
  101. ),
  102. RaisedButton(
  103. onPressed: () {
  104. Navigator.push(context, MaterialPageRoute(builder: (_) {
  105. return Logger();
  106. }));
  107. },
  108. child: Text('打开日志视图'),
  109. ),
  110. RaisedButton(
  111. onPressed: () {
  112. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  113. // onSuccess: (params){
  114. // Logger.log("onSuccess#$params");
  115. // },
  116. // onCache: (params){
  117. // Logger.log("onCache#$params");
  118. // });
  119. testPost();
  120. },
  121. child: Text('测试接口'),
  122. ),
  123. RaisedButton(
  124. onPressed: () {
  125. Navigator.push(context, MaterialPageRoute(builder: (_) {
  126. return TaobaoImageView();
  127. }));
  128. },
  129. child: Text('抓淘宝图片'),
  130. ),
  131. RaisedButton(
  132. onPressed: () {
  133. TaobaoAuth.auth(context);
  134. },
  135. child: Text('淘宝授权'),
  136. ),
  137. RaisedButton(
  138. onPressed: () {
  139. //
  140. Dio dio = Dio();
  141. dio.get(
  142. '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')
  143. .then((value) {
  144. Logger.debug(value.realUri.toString());
  145. });
  146. },
  147. child: Text('获取重定向地址'),
  148. ),
  149. RaisedButton(
  150. onPressed: () {
  151. Jdsdk.openUrl(
  152. url: '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');
  153. },
  154. child: Text('打开京东详情'),
  155. ),
  156. RaisedButton(
  157. onPressed: () async {
  158. 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';
  159. String baseUrl = detailUrl.getBaseUrl();
  160. if (!baseUrl.contains('jd.com')) {
  161. Dio dio = Dio();
  162. var responds = await dio.get(detailUrl);
  163. detailUrl = responds.realUri.toString();
  164. }
  165. Logger.debug(detailUrl);
  166. Jdsdk.openUrl(
  167. url
  168. :
  169. detailUrl
  170. );
  171. },
  172. child: Text('嗨如意转链打开京东'),
  173. ),
  174. RaisedButton(
  175. onPressed: () async {
  176. const url = 'weixin://';
  177. if (await canLaunch(url)) {
  178. await launch(url);
  179. } else {
  180. throw 'Could not launch $url';
  181. }
  182. },
  183. child: Text('url scheme打开app'),
  184. ),
  185. ],
  186. ),
  187. ),
  188. ),
  189. );
  190. }
  191. void testPost() async {
  192. var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {
  193. 'ids': [7]
  194. });
  195. print("cahced ${cached?.toString()}");
  196. var param = await NetUtil.post('/api/v1/mod',
  197. params: {
  198. 'ids': [7]
  199. },
  200. method: NetMethod.POST);
  201. print('apapapsdjfdsjf: ${param?.toString()}');
  202. }
  203. }