wxnews.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>洪楼Plus-让买房更省心</title>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  8. <meta content="telephone=no, address=no" name="format-detection" />
  9. <style>
  10. html,body,div,span,iframe,h1,h2,h3,h4,h5,h6,p,pre,a,address,img,small,strong,sub,sup,tt,b,i,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section,canvas,audio,video {
  11. margin: 0;
  12. padding: 0;
  13. border: 0;
  14. font-size: 100%;
  15. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  16. vertical-align: baseline
  17. }
  18. article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
  19. display: block
  20. }
  21. ol,
  22. ul {
  23. list-style: none
  24. }
  25. table {
  26. border-collapse: collapse;
  27. border-spacing: 0
  28. }
  29. button,
  30. img,
  31. fieldset {
  32. display: block;
  33. border: 0
  34. }
  35. button,
  36. html input[type=button],
  37. input[type=reset],
  38. input[type=submit] {
  39. -webkit-appearance: button;
  40. cursor: pointer;
  41. padding: 0
  42. }
  43. input[type=checkbox],
  44. input[type=radio] {
  45. cursor: pointer;
  46. padding: 0
  47. }
  48. a {
  49. color: #4183c4;
  50. text-decoration: none
  51. }
  52. a:hover {
  53. text-decoration: none
  54. }
  55. html {
  56. -ms-text-size-adjust: 100%;
  57. -webkit-text-size-adjust: 100%
  58. }
  59. body {
  60. font-family: "Microsoft YaHei", "Segoe UI", "Lucida Grande", Helvetica, Arial, FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3", FontAwesome, sans-serif;
  61. font-weight: 400;
  62. line-height: 1.42;
  63. min-width: 320px;
  64. max-width: 640px;
  65. margin: 0 auto;
  66. color: #333;
  67. font-size: 16px;
  68. background: #fff;
  69. -webkit-font-smoothing: antialiased;
  70. -moz-osx-font-smoothing: grayscale
  71. }
  72. /*主体css*/
  73. .app-view{
  74. padding: 0 16px 20px;
  75. }
  76. .app-view img{
  77. max-width: 100%;
  78. height: auto!important;
  79. }
  80. .app-view .title{
  81. margin: 20px 0;
  82. font-size: 24px;
  83. }
  84. .app-view .other-info{
  85. margin-bottom: 10px;
  86. color: #b2b2b2;
  87. }
  88. #content, #content *, #content div, #content p, #content span {
  89. word-break: break-all!important;
  90. }
  91. </style>
  92. <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  93. </head>
  94. <body>
  95. <div id="app">
  96. <div class="app-view">
  97. <h3 class="title" id="title"></h3>
  98. <p class="other-info">
  99. <span style="color:#576b95;padding-right:10px;font-weight: bold;" Id="from"></span>
  100. <span id="time"></span>
  101. </p>
  102. <div id="content"></div>
  103. </div>
  104. </div>
  105. </body>
  106. </html>
  107. <script>
  108. // 封装ajax
  109. function ajax(list) {
  110. if (XMLHttpRequest) {
  111. var req = new XMLHttpRequest();
  112. } else {
  113. var req = new ActiveXObject("Microsoft.XMLHTTP");
  114. }
  115. var type = list.type || 'get';
  116. var data = list.data || '';
  117. var isAysnch = list.isAysnch || true;
  118. if (type == 'get') {
  119. req.open(type, list.url + "?" + data, isAysnch);
  120. req.send(null);
  121. } else {
  122. // console.log(req)
  123. // req.responseType = 'json'
  124. req.open(type, list.url, isAysnch);
  125. req.send(data);
  126. }
  127. req.onload = function () {
  128. var d = req.responseText;
  129. list.success(d);
  130. }
  131. }
  132. //获取路由参数
  133. function getRouteQuery () {
  134. var searchStr = window.location.search.slice(1)
  135. var searchArr = searchStr.split('&')
  136. var query = {}
  137. for (var i = 0; i < searchArr.length; i++) {
  138. var item = searchArr[i].split('=')
  139. query[item[0]] = item[1]
  140. }
  141. return query
  142. }
  143. //请求数据
  144. var novelId = getRouteQuery().id
  145. if (novelId) {
  146. var formData = new FormData();
  147. formData.append("id", novelId);
  148. ajax({
  149. type:'post',
  150. url:'https://api.honglouplus.com/api/h5/information',
  151. data: formData,
  152. success:function(msg){
  153. var res = JSON.parse(msg)
  154. var newsInfo = res.data
  155. var content = newsInfo.content
  156. document.getElementById('content').innerHTML = content
  157. var timeArr = newsInfo.create_at.split(' ')
  158. var time = timeArr[0]
  159. document.getElementById('title').innerHTML = newsInfo.title
  160. document.getElementById('time').innerHTML = time
  161. document.getElementById('from').innerHTML = newsInfo.author
  162. value = content.replace(/(\n)/g, "");
  163. value = value.replace(/(\t)/g, "");
  164. value = value.replace(/(\r)/g, "");
  165. value = value.replace(/<\/?[^>]*>/g, "");
  166. value = value.replace(/\s*/g, "");
  167. value = value.replace(/&nbsp;/ig, "");
  168. var desc = value.substring(0, 40);
  169. // console.log(desc)
  170. configJsSDKAndDoSomething(res.jssdk, newsInfo.title, newsInfo.pri_image, desc)
  171. }
  172. })
  173. } else {
  174. window.alert('缺少文章ID')
  175. }
  176. var shareImgUrl = 'https://icon.honglouplus.com/plus.png';
  177. function configJsSDKAndDoSomething(config, title, imgUrl, desc){
  178. wx.config({
  179. debug: false,
  180. appId: config.appId,
  181. timestamp: config.timestamp,
  182. nonceStr: config.nonceStr,
  183. signature: config.signature,
  184. jsApiList: config.jsApiList,
  185. openTagList: ['wx-open-launch-weapp'],
  186. })
  187. wx.error(function(error){
  188. console.log(error);
  189. });
  190. wx.ready(function () {
  191. wx.updateAppMessageShareData({
  192. title: title,
  193. desc: desc,
  194. link: location.href,
  195. imgUrl: imgUrl,
  196. success: function () {
  197. console.log("success");
  198. }
  199. });
  200. wx.updateTimelineShareData({
  201. title: title,
  202. link: location.href,
  203. imgUrl: imgUrl,
  204. success: function () {
  205. console.log("success2");
  206. }
  207. });
  208. });
  209. }
  210. </script>