saveKeys.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. app.log(res)
  24. if (res.data.code == 5) {
  25. wx.showModal({
  26. title: '提示',
  27. content: res.data.msg || "保存失败",
  28. cancelText: "取消",
  29. confirmText: "更新",
  30. success: function (item) {
  31. if (item.confirm) {
  32. app.log("更新", res.data.forceUpdate);
  33. saveKeys(that, res.data.forceUpdate);
  34. } else {
  35. }
  36. }
  37. });
  38. }else if(res.data.code > 0){
  39. wx.showModal({
  40. title: '提示',
  41. content: res.data.msg || "保存失败",
  42. showCancel: false,
  43. success: function (res) {
  44. }
  45. });
  46. return;
  47. }
  48. app.sslKeySaveSync(res.data);
  49. },
  50. fail : function(res) {
  51. app.sslKeySaveSync(appConfig.networkError);
  52. }
  53. })
  54. }
  55. module.exports = saveKeys