bindPhone.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * @Author: xiaolin
  3. * @Date: 2022-10-12 12:09:56
  4. * @LastEditors: xiaolin
  5. * @LastEditTime: 2022-10-21 15:38:28
  6. * @Description: file content
  7. * @FilePath: \image.platform.com\xyxJsSdkV2\src\bindPhone.js
  8. */
  9. import request from "../utils/request.js";
  10. import { checkLoginStatus } from "../src/login.js";
  11. /**
  12. * @description: 绑定手机号
  13. * @param {
  14. phone: "1341341340",
  15. code: "123456"
  16. } data
  17. * @return {*}
  18. */
  19. export const bindPhone = async (data) => {
  20. console.log("bindPhone入参"+JSON.stringify(data));
  21. try {
  22. const needValus = ["phone", "code"];
  23. needValus.forEach((value) => {
  24. if (data[value] === undefined) {
  25. return Promise.reject({
  26. msg: `invalid ${value}`,
  27. });
  28. }
  29. });
  30. const res = await request.api("COMMON", {
  31. do: "bindPhone",
  32. phone: data.phone,
  33. code: data.code,
  34. });
  35. //要重新获取一次用户信息
  36. await checkLoginStatus();
  37. return Promise.resolve(res);
  38. } catch (error) {
  39. return Promise.reject(error);
  40. }
  41. };
  42. /**
  43. * @description: 获取手机验证码
  44. * @param {
  45. phone: "1341341340"
  46. } data
  47. * @return {*}
  48. */
  49. export const getBindPhoneCode = async (data) => {
  50. console.log("getBindPhoneCode入参"+JSON.stringify(data));
  51. try {
  52. const needValus = ["phone"];
  53. needValus.forEach((value) => {
  54. if (data[value] === undefined) {
  55. return Promise.reject(`invalid ${value}`);
  56. }
  57. });
  58. const res = await request.api("COMMON", {
  59. do: "getBindPhoneCode",
  60. phone: data.phone,
  61. });
  62. return Promise.resolve(res);
  63. } catch (error) {
  64. return Promise.reject(error);
  65. }
  66. };