| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import cloudApi from "../apis/cloudApi";
- import { postApi } from "../apis/api";
- function wxSetSessionKey() {
- return new Promise((resolve, reject) => {
- wx.login({
- success: async (res) => {
- if (res.code) {
- let { data } = await postApi("/wx/getOpenId", {
- code: res.code,
- });
- if (data.status === 0) {
- let { openId } = data.result;
- // openId = "oiOWR5ch23L_mD2uYwSemzedD2dG8I2323221";
- wx.setStorageSync("openId", openId);
- resolve({
- status: 0,
- openId,
- });
- } else {
- wx.showToast({
- title: `系统错误: status: ${data.status} , ${data.msg}`,
- icon: "none",
- duration: 5000,
- });
- reject({
- openId: "",
- status: 1,
- });
- }
- } else {
- wx.showToast({
- title: "获取openId失败,请重新进入小程序",
- icon: "none",
- duration: 5000,
- });
- reject({
- openId: "",
- status: 1,
- });
- }
- },
- fail: (e) => {
- wx.showToast({
- title: "获取openId失败,请重新进入小程序",
- icon: "none",
- duration: 5000,
- });
- reject({
- openId: "",
- status: 1,
- });
- },
- });
- });
- }
- function getUserProfile() {
- return new Promise((resolve, reject) => {
- wx.getUserProfile({
- desc: "'用于完善用户信息",
- success: (e) => {
- let { userInfo } = e;
- resolve({
- status: 0,
- userInfo,
- });
- },
- fail: (e) => {
- resolve({
- errMsg: e.errMsg,
- status: 1,
- });
- },
- });
- });
- }
- function subMsg() {
- return new Promise((resolve, reject) => {
- wx.requestSubscribeMessage({
- tmplIds: ["q1joCPFWjhAxSJtrZ30QFi_aA9LVva4PQZmBcxZIPhU"],
- success: (res) => {
- console.log(res);
- },
- complete: (e) => {
- console.log(e);
- },
- });
- });
- }
- module.exports = {
- wxSetSessionKey,
- getUserProfile,
- subMsg,
- };
|