privatekey.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. publicKey : "",
  11. privateKey : "",
  12. background : "",
  13. },
  14. inputAction: function (e) {
  15. var name = e.target.dataset.id;
  16. app.log(name, e.detail.value);
  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. app.log(e);
  42. res.code = 400;
  43. res.msg = e;
  44. }
  45. app.verifyKeysSuccessSync(res);
  46. //common.verifyKeys(this.data.publicKey, this.data.privateKey);
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. this.setData({
  53. background: utils.getBackground()
  54. });
  55. wx.setNavigationBarTitle({
  56. title: '验证私钥'
  57. });
  58. app.verifyKeysSuccessSync = res => {
  59. app.log(res)
  60. if(!res || (res.code && res.code > 0)) {
  61. app.warning(res.msg || "验证失败,请检查您的私钥~");
  62. return;
  63. }
  64. //验证成功有,将公私钥保存到sslKey和serverInfo
  65. //更新本地公私钥
  66. wx.setStorageSync(appConfig.storeKeys.sslKeys, { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey });
  67. //更新serverInfo中用户的公私钥
  68. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  69. serverInfo.sslKeys = { 'publicKey': this.data.publicKey, 'privateKey': this.data.privateKey };
  70. app.log("更新 serverInfo", serverInfo);
  71. wx.setStorageSync(appConfig.storeKeys.serverInfo, serverInfo);
  72. wx.showModal({
  73. title: '温馨提示',
  74. content: '私钥校验成功',
  75. showCancel: false,
  76. success: function (item) {
  77. app.globalData.isReloadIcon = true;
  78. wx.navigateBack();
  79. }
  80. })
  81. }
  82. var serverInfo = wx.getStorageSync(appConfig.storeKeys.serverInfo);
  83. this.setData({
  84. "publicKey": utils.getPublicKey()
  85. });
  86. },
  87. /**
  88. * 生命周期函数--监听页面初次渲染完成
  89. */
  90. onReady: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面隐藏
  99. */
  100. onHide: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面卸载
  104. */
  105. onUnload: function () {
  106. },
  107. /**
  108. * 页面相关事件处理函数--监听用户下拉动作
  109. */
  110. onPullDownRefresh: function () {
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. },
  117. /**
  118. * 用户点击右上角分享
  119. */
  120. onShareAppMessage: function () {
  121. }
  122. })