saveKeys.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const app = getApp();
  2. const appConfig = require("../config");
  3. const utils = require("../utils/util");
  4. var saveKeys = function (that, forceUpdate) {
  5. var header = {
  6. 'content-type': 'application/x-www-form-urlencoded',
  7. 'cookie': wx.getStorageSync(appConfig.storeKeys.sessionId)
  8. };
  9. var data = {
  10. 'public_key': that.data.publicKey,
  11. 'private_key' : that.data.privateKey,
  12. };
  13. if (forceUpdate) {
  14. data.forceUpdate = forceUpdate;
  15. }
  16. wx.request({
  17. url: utils.getUrl('savePublicKey'),
  18. data : data,
  19. header: header,
  20. method : 'POST',
  21. dataType: 'json',
  22. success: function (res) {
  23. if (res.data.code == 5) {
  24. wx.showModal({
  25. title: '提示',
  26. content: res.data.msg || "保存失败",
  27. cancelText: "取消",
  28. confirmText: "更新",
  29. success: function (item) {
  30. if (item.confirm) {
  31. saveKeys(that, res.data.forceUpdate);
  32. } else {
  33. }
  34. }
  35. });
  36. }else if(res.data.code > 0){
  37. wx.showModal({
  38. title: '提示',
  39. content: res.data.msg || "保存失败",
  40. showCancel: false,
  41. success: function (res) {
  42. }
  43. });
  44. return;
  45. }
  46. app.sslKeySaveSync(res.data);
  47. },
  48. fail : function(res) {
  49. app.sslKeySaveSync(appConfig.networkError);
  50. }
  51. })
  52. }
  53. module.exports = saveKeys