edit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-04-20
  8. * Time: 15:38
  9. */
  10. ?>
  11. <div id="app" v-cloak>
  12. <el-card v-loading="dataLoading" class="box-card" shadow="never"
  13. style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  14. <div slot="header">
  15. <span>支付宝小程序基础设置</span>
  16. <div style="float: right; margin: -5px 0">
  17. <el-button class="button-item" :loading="btnLoading" type="primary" @click="submit('ruleForm')"
  18. size="small">
  19. 保存
  20. </el-button>
  21. </div>
  22. </div>
  23. <div class="form-body">
  24. <el-form :model="ruleForm" :rules="rules" size="small" ref="ruleForm" label-width="150px">
  25. <el-row>
  26. <el-col :span="24">
  27. <el-form-item label="使用证书版" prop="is_use_cert">
  28. <el-switch
  29. v-model="ruleForm.is_use_cert"
  30. :active-value="1"
  31. :inactive-value="0"
  32. active-text="证书版"
  33. inactive-text="公钥版">
  34. </el-switch>
  35. </el-form-item>
  36. <el-form-item label="商户ID" prop="mch_id">
  37. <el-input v-model="ruleForm.mch_id"></el-input>
  38. </el-form-item>
  39. <el-form-item label="小程序名称" prop="name">
  40. <el-input v-model="ruleForm.name"></el-input>
  41. </el-form-item>
  42. <el-form-item label="小程序app_id" prop="app_id">
  43. <el-input v-model="ruleForm.app_id"></el-input>
  44. </el-form-item>
  45. <el-form-item label="AES密钥" prop="encryptKey">
  46. <el-input v-model="ruleForm.encryptKey"></el-input>
  47. </el-form-item>
  48. <el-form-item label="应用私钥" prop="secret">
  49. <el-input @focus="hidden.secret = false" v-if="hidden.secret" readonly placeholder="已隐藏内容,点击查看或编辑"></el-input>
  50. <el-input v-else v-model.trim="ruleForm.merchantPrivateKey"></el-input>
  51. </el-form-item>
  52. <!-- <el-form-item label="应用公钥证书" prop="merchantCertPath">-->
  53. <!-- <el-col :span="10">-->
  54. <!-- <el-input v-model="ruleForm.merchantCertPath" :placeholder="ruleForm.merchantCertPath" :disabled="true"></el-input>-->
  55. <!-- </el-col>-->
  56. <!-- <el-col :span="4">-->
  57. <!-- <input ref="merchantCertPath" type="file" accept=".key" :multiple="multiple" style="display: none"-->
  58. <!-- @change="handleChange">-->
  59. <!-- <el-button size="small" @click="uploadPem('merchantCertPath')">上传文件</el-button>-->
  60. <!-- </el-col>-->
  61. <!-- </el-form-item>-->
  62. <div v-show="ruleForm.is_use_cert == 1">
  63. <el-form-item label="应用公钥" prop="merchantCertPath">
  64. <el-col :span="10">
  65. <el-input v-model="ruleForm.merchantCertPath" :placeholder="ruleForm.merchantCertPath" :disabled="true"></el-input>
  66. </el-col>
  67. <el-col :span="4">
  68. <input ref="merchantCertPath" type="file" accept=".key" :multiple="multiple" style="display: none"
  69. @change="handleChange">
  70. <el-button size="small" @click="uploadPem('merchantCertPath')">上传文件</el-button>
  71. </el-col>
  72. </el-form-item>
  73. <el-form-item label="支付宝根证书" prop="alipayRootCertPath">
  74. <el-col :span="10">
  75. <el-input v-model="ruleForm.alipayRootCertPath" :placeholder="ruleForm.alipayRootCertPath" :disabled="true"></el-input>
  76. </el-col>
  77. <el-col :span="4">
  78. <input ref="alipayRootCertPath" type="file" accept=".key" :multiple="multiple" style="display: none"
  79. @change="handleChangeAlipayRootCertPath">
  80. <el-button size="small" @click="uploadPem('alipayRootCertPath')">上传文件</el-button>
  81. </el-col>
  82. </el-form-item>
  83. </div>
  84. <el-form-item label="支付宝公钥证书" prop="alipayCertPath">
  85. <el-col :span="10">
  86. <el-input v-model="ruleForm.alipayCertPath" :placeholder="ruleForm.alipayCertPath" :disabled="true"></el-input>
  87. </el-col>
  88. <el-col :span="4">
  89. <input ref="alipayCertPath" type="file" accept=".key" :multiple="multiple" style="display: none"
  90. @change="handleChangeAlipayCertPath">
  91. <el-button size="small" @click="uploadPem('alipayCertPath')">上传文件</el-button>
  92. </el-col>
  93. </el-form-item>
  94. <el-form-item label="拥有授权手机号能力" prop="can_auth_phone">
  95. <el-switch
  96. v-model="ruleForm.can_auth_phone"
  97. :active-value="1"
  98. :inactive-value="0" active-text="是"
  99. inactive-text="否">
  100. </el-switch>
  101. </el-form-item>
  102. <!-- <el-form-item label="支付宝根证书" prop="alipayRootCertPath">-->
  103. <!-- <el-col :span="10">-->
  104. <!-- <el-input v-model="ruleForm.alipayRootCertPath" :placeholder="ruleForm.alipayRootCertPath" :disabled="true"></el-input>-->
  105. <!-- </el-col>-->
  106. <!-- <el-col :span="4">-->
  107. <!-- <input ref="alipayRootCertPath" type="file" accept=".key" :multiple="multiple" style="display: none"-->
  108. <!-- @change="handleChangeAlipayRootCertPath">-->
  109. <!-- <el-button size="small" @click="uploadPem('alipayRootCertPath')">上传文件</el-button>-->
  110. <!-- </el-col>-->
  111. <!-- </el-form-item>-->
  112. </el-col>
  113. </el-row>
  114. </el-form>
  115. </div>
  116. </el-card>
  117. <el-dialog v-loading="posterLoading" title="体验版" :visible.sync="sharePop" width="5%" center :close-on-click-modal="false">
  118. <div class="share-pop-model" flex>
  119. <div style="width: 180px; height: 180px;background: #F2F2F2;margin-left: 170px;" flex="main:center cross:center">
  120. <el-image style="width: 144px; height: 144px;" :src="qrcode" center></el-image>
  121. </div>
  122. </div>
  123. </el-dialog>
  124. </div>
  125. <script>
  126. new Vue({
  127. el: '#app',
  128. data() {
  129. return {
  130. hidden: {
  131. app_id: true,
  132. secret: true,
  133. original_id: true,
  134. // mch_id: false,
  135. // pay_secret: true,
  136. // cert_pem: true,
  137. // key_pem: true,
  138. },
  139. dataLoading: false,
  140. rules: {
  141. name: [
  142. {required: true, message: '请输入小程序名称', trigger: 'change'},
  143. ],
  144. app_id: [
  145. {required: true, message: '请输入app_id', trigger: 'change'},
  146. ],
  147. mch_id: [
  148. {required: true, message: '请输入mch_id', trigger: 'change'},
  149. ],
  150. },
  151. btnLoading: false,
  152. btnLoadings: false,
  153. cardLoading: false,
  154. mini_program: '',
  155. ruleForm: {
  156. name: '',
  157. app_id: '',
  158. merchantPrivateKey: '',
  159. merchantCertPath: '',
  160. alipayPublicKey: '',
  161. alipayRootCertPath: '',
  162. alipayCertPath: '',
  163. encryptKey:'',
  164. mch_id: '',
  165. is_use_cert: 0,
  166. can_auth_phone: 0,
  167. },
  168. pem_value: '',
  169. qrcode:'',
  170. sharePop:false,
  171. posterLoading: false,
  172. multiple: false
  173. };
  174. },
  175. created() {
  176. this.loadData();
  177. },
  178. methods: {
  179. loadData() {
  180. this.loading = true;
  181. request({
  182. params: {
  183. r: 'mall/alipay-mini/edit',
  184. },
  185. }).then(e => {
  186. this.loading = false;
  187. if (e.data.code === 0) {
  188. if (!isEmpty(e.data.data.mini_program)) {
  189. this.ruleForm = e.data.data.mini_program;
  190. }
  191. } else {
  192. this.$message.error(e.data.msg);
  193. }
  194. }).catch(e => {
  195. });
  196. },
  197. qrcodePicUrl(e) {
  198. if (e.length) {
  199. this.ruleForm.qrcode = e[0].url;
  200. }
  201. },
  202. submit(formName) {
  203. this.$refs[formName].validate((valid) => {
  204. let self = this;
  205. if (valid) {
  206. self.btnLoading = true;
  207. request({
  208. params: {
  209. r: 'mall/alipay-mini/edit'
  210. },
  211. method: 'post',
  212. data: {
  213. form: self.ruleForm,
  214. }
  215. }).then(e => {
  216. self.btnLoading = false;
  217. if (e.data.code === 0) {
  218. self.$message.success(e.data.msg);
  219. } else {
  220. self.$message.error(e.data.msg);
  221. }
  222. }).catch(e => {
  223. self.$message.error(e.data.msg);
  224. self.btnLoading = false;
  225. });
  226. } else {
  227. console.log('error submit!!');
  228. return false;
  229. }
  230. });
  231. },
  232. uploadPem(key) {
  233. this.pem_value = key;
  234. console.log(this.$refs)
  235. this.$refs[key].value = null;
  236. this.$refs[key].click();
  237. },
  238. handleChange(e){
  239. var rawFiles = e.target.files;
  240. if (rawFiles.length > 1) {
  241. this.$message.error('最多一次只能上传一个文件。')
  242. return;
  243. }
  244. let file = {
  245. _complete: false,
  246. response: null,
  247. rawFile: rawFiles[0],
  248. };
  249. let formData = new FormData();
  250. const params = {};
  251. params['r'] = 'mall/file/upload';
  252. for (let i in this.params) {
  253. params[i] = this.params[i];
  254. }
  255. for (let i in this.fields) {
  256. formData.append(i, this.fields[i]);
  257. }
  258. formData.append('file', file.rawFile, file.rawFile.name);
  259. this.$request({
  260. headers: {'Content-Type': 'multipart/form-data'},
  261. params: params,
  262. method: 'post',
  263. data: formData,
  264. }).then(e => {
  265. if (e.data.code === 0) {
  266. this.$set(this.ruleForm, 'merchantCertPath', e.data.data.path)
  267. this.$message.success('上传成功');
  268. } else {
  269. this.$message.error(e.data.msg);
  270. }
  271. }).catch(e => {
  272. this.$message.error('上传失败');
  273. });
  274. },
  275. handleChangeAlipayCertPath(e){
  276. var rawFiles = e.target.files;
  277. if (rawFiles.length > 1) {
  278. this.$message.error('最多一次只能上传一个文件。')
  279. return;
  280. }
  281. let file = {
  282. _complete: false,
  283. response: null,
  284. rawFile: rawFiles[0],
  285. };
  286. let formData = new FormData();
  287. const params = {};
  288. params['r'] = 'mall/file/upload';
  289. for (let i in this.params) {
  290. params[i] = this.params[i];
  291. }
  292. for (let i in this.fields) {
  293. formData.append(i, this.fields[i]);
  294. }
  295. formData.append('file', file.rawFile, file.rawFile.name);
  296. this.$request({
  297. headers: {'Content-Type': 'multipart/form-data'},
  298. params: params,
  299. method: 'post',
  300. data: formData,
  301. }).then(e => {
  302. if (e.data.code === 0) {
  303. this.$set(this.ruleForm, 'alipayCertPath', e.data.data.path)
  304. this.$message.success('上传成功');
  305. } else {
  306. this.$message.error(e.data.msg);
  307. }
  308. }).catch(e => {
  309. this.$message.error('上传失败');
  310. });
  311. },
  312. handleChangeAlipayRootCertPath(e){
  313. var rawFiles = e.target.files;
  314. if (rawFiles.length > 1) {
  315. this.$message.error('最多一次只能上传一个文件。')
  316. return;
  317. }
  318. let file = {
  319. _complete: false,
  320. response: null,
  321. rawFile: rawFiles[0],
  322. };
  323. let formData = new FormData();
  324. const params = {};
  325. params['r'] = 'mall/file/upload';
  326. for (let i in this.params) {
  327. params[i] = this.params[i];
  328. }
  329. for (let i in this.fields) {
  330. formData.append(i, this.fields[i]);
  331. }
  332. formData.append('file', file.rawFile, file.rawFile.name);
  333. this.$request({
  334. headers: {'Content-Type': 'multipart/form-data'},
  335. params: params,
  336. method: 'post',
  337. data: formData,
  338. }).then(e => {
  339. if (e.data.code === 0) {
  340. this.$set(this.ruleForm, 'alipayRootCertPath', e.data.data.path)
  341. this.$message.success('上传成功');
  342. } else {
  343. this.$message.error(e.data.msg);
  344. }
  345. }).catch(e => {
  346. this.$message.error('上传失败');
  347. });
  348. },
  349. }
  350. });
  351. </script>