creat_wxauthorize_uri.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>creat_wxauthorize_uri</title>
  8. <link
  9. rel="stylesheet"
  10. href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
  11. />
  12. <script src="https://unpkg.com/vue@2.6.12/dist/vue.js"></script>
  13. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  14. </head>
  15. <body>
  16. <div id="app">
  17. <el-row>
  18. <el-col :offset="6" :span="12">
  19. <h2 style="text-align: center">生成微信网页授权地址</h2>
  20. <el-tabs v-model="activeName" @tab-click="handleClick">
  21. <el-tab-pane label="微信授权链接" name="first">
  22. <el-form ref="form" :model="form" label-width="100px">
  23. <el-form-item label="main-frame">
  24. <el-select
  25. v-model="branchIndex"
  26. clearable
  27. filterable
  28. placeholder="请选择"
  29. >
  30. <el-option
  31. v-for="item in branchList"
  32. :key="item.value"
  33. :label="item.label"
  34. :value="item.value"
  35. >
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="接口前缀">
  40. <el-select
  41. v-model="form.prefix"
  42. clearable
  43. filterable
  44. placeholder="请选择"
  45. >
  46. <el-option
  47. v-for="item in prefixList"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value"
  51. >
  52. </el-option>
  53. </el-select>
  54. </el-form-item>
  55. <!-- <el-form-item label="wxAuthUri">
  56. <el-input v-model="wxAuthUri" disabled>
  57. <template slot="prepend">微信网页授权地址</template>
  58. </el-input>
  59. </el-form-item> -->
  60. <el-form-item label="appid">
  61. <el-input v-model="form.appid" clearable></el-input>
  62. </el-form-item>
  63. <el-form-item label="redirect_uri">
  64. <el-input v-model="form.redirect_uri" clearable>
  65. <template slot="prepend">
  66. <el-tooltip
  67. class="item"
  68. effect="dark"
  69. :content="auth2Uri"
  70. placement="top-start"
  71. >
  72. <el-button>auth2Uri</el-button>
  73. </el-tooltip></template
  74. >
  75. </el-input>
  76. </el-form-item>
  77. <el-form-item label="response_type">
  78. <el-input
  79. v-model="form.response_type"
  80. disabled
  81. clearable
  82. ></el-input>
  83. </el-form-item>
  84. <el-form-item label="scope">
  85. <el-input
  86. v-model="form.scope"
  87. disabled
  88. readonly
  89. clearable
  90. ></el-input>
  91. </el-form-item>
  92. <el-form-item label="state">
  93. <el-input v-model="form.state" clearable> </el-input>
  94. </el-form-item>
  95. <el-form-item>
  96. <el-button type="primary" @click="onSubmit"
  97. >立即创建</el-button
  98. >
  99. </el-form-item>
  100. </el-form>
  101. </el-tab-pane>
  102. <!-- <el-tab-pane label="微信授权后链接" name="second"> </el-tab-pane> -->
  103. </el-tabs>
  104. </el-col>
  105. </el-row>
  106. <el-link
  107. href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html"
  108. ></el-link>
  109. <el-dialog title="提示" :visible.sync="dialogVisible" center width="50%">
  110. <span slot="footer" class="dialog-footer">
  111. <div class="print" style="text-align: left">{{print}}</div>
  112. <el-button @click="dialogVisible = false">取 消</el-button>
  113. <el-button type="primary" @click="onConfirm">复制</el-button>
  114. </span>
  115. </el-dialog>
  116. </div>
  117. <script>
  118. new Vue({
  119. el: "#app",
  120. data: {
  121. message: "Hello Vue.js!",
  122. activeName: "first",
  123. branchList: [
  124. { label: "超级前台", value: 0, key: "main" },
  125. { label: "华融", value: 1, key: "huarong" },
  126. { label: "潮宝", value: 2, key: "schaobao" },
  127. { label: "珠江啤酒", value: 3, key: "zhupi" },
  128. ],
  129. prefixList: [
  130. {
  131. label: "超级前台",
  132. value: "https://superdesk.avic-s.com/super_cloud",
  133. key: "superdesk.avic-s.com",
  134. },
  135. {
  136. label: "广电",
  137. value: "https://gd.szmgzhly.com/super_cloud",
  138. key: "gd.szmgzhly.com",
  139. },
  140. ],
  141. branchIndex: 0,
  142. wxAuthUri: "https://open.weixin.qq.com/connect/oauth2/authorize",
  143. auth2Uri:
  144. "https://superdesk.avic-s.com/super_cloud/api/wechat/front/auth2?redirectUrl=",
  145. form: {
  146. appid: "wx8f5a07e8746f85e3",
  147. redirect_uri: "https://superdesk.avic-s.com/super_cloud/wx/main",
  148. response_type: "code",
  149. scope: "snsapi_base",
  150. state: 10,
  151. },
  152. dialogVisible: false,
  153. print: "",
  154. },
  155. methods: {
  156. handleClick(tab, event) {
  157. console.log(tab, event);
  158. },
  159. copyToClipboard(text) {
  160. try {
  161. let node = document.createElement("input");
  162. document.body.appendChild(node);
  163. node.value = text;
  164. node.select();
  165. document.execCommand("copy");
  166. document.body.removeChild(node); // 执行浏览器复制命令
  167. console.log("复制成功");
  168. } catch (e) {
  169. console.log("复制失败");
  170. }
  171. // let node = document.getElementById("print");
  172. // document.createElement("print");
  173. // try {
  174. // let range = document.createRange();
  175. // range.selectNodeContents(node);
  176. // let selection = document.getSelection();
  177. // selection.removeAllRanges();
  178. // selection.addRange(range);
  179. // document.execCommand("copy"); // 执行浏览器复制命令
  180. // console.log("复制成功");
  181. },
  182. onSubmit() {
  183. // https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html
  184. const { form, wxAuthUri, auth2Uri } = this;
  185. const data = Object.assign({}, form);
  186. const redirect_uri = `${auth2Uri}${data.redirect_uri}`;
  187. console.log(redirect_uri);
  188. data.redirect_uri = redirect_uri;
  189. const query = Object.keys(data)
  190. .map((key) => key + "=" + encodeURIComponent(data[key]))
  191. .join("&")
  192. .concat("#wechat_redirect");
  193. this.print = `${wxAuthUri}?${query}`;
  194. this.dialogVisible = true;
  195. this.onConfirm();
  196. },
  197. onConfirm() {
  198. this.copyToClipboard(this.print);
  199. this.$message({
  200. message: "复制成功",
  201. type: "success",
  202. });
  203. },
  204. },
  205. });
  206. </script>
  207. </body>
  208. </html>