privatekey.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const app = getApp()
  2. const appConfig = require('../../config')
  3. const common = require('../../common')
  4. const utils = require('../../utils/util.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. title:"验证私钥",
  11. publicKey : "",
  12. privateKey : "",
  13. background : "",
  14. },
  15. inputAction: function (e) {
  16. var name = e.target.dataset.id;
  17. var data = {};
  18. data[name] = e.detail.value;
  19. this.setData(data);
  20. },
  21. resetPrivateKey : function(){
  22. wx.navigateTo({
  23. url: '/pages/reset/reset',
  24. })
  25. },
  26. verifyPrivateKey: function(){
  27. if(this.data.publicKey == "" || this.data.privateKey == "") {
  28. app.warning("公私钥不能为空~")
  29. return;
  30. }
  31. var res = {
  32. code : 0,
  33. msg: "恭喜您,您的公私钥校验成功!"
  34. };
  35. try{
  36. if (!utils.verifySslKey(this.data.publicKey, this.data.privateKey)) {
  37. res.code = 1;
  38. res.msg = "校验失败,您的公私钥不匹配,请查证后再试!";
  39. }
  40. }catch(e) {
  41. res.code = 400;
  42. res.msg = e;
  43. }
  44. app.verifyKeysSuccessSync(res);
  45. //common.verifyKeys(this.data.publicKey, this.data.privateKey);
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. this.setData({
  52. background: utils.getBackground()
  53. });
  54. wx.setNavigationBarTitle({
  55. title: '验证私钥'
  56. });
  57. app.verifyKeysSuccessSync = res => {
  58. if(!res || (res.code && res.code > 0)) {
  59. app.warning(res.msg || "验证失败,请检查您的私钥~");
  60. return;
  61. }
  62. //验证成功有,将公私钥保存到sslKey和serverInfo
  63. //更新本地公私钥
  64. wx.setStorageSync(appConfig.storeKeys.sslKeys, { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey });
  65. //更新serverInfo中用户的公私钥
  66. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  67. serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
  68. wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
  69. wx.showModal({
  70. title: '温馨提示',
  71. content: '私钥校验成功',
  72. showCancel: false,
  73. success: function (item) {
  74. app.globalData.isReloadIcon = true;
  75. wx.navigateBack();
  76. }
  77. })
  78. }
  79. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  80. this.setData({
  81. "publicKey": utils.getPublicKey()
  82. });
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })