Commit 2f6cb1db by chenhui

小程序订阅消息配置

parent ec017d63
...@@ -2,8 +2,13 @@ import {requestPOST,requestGET} from "@/utils/request.js"; ...@@ -2,8 +2,13 @@ import {requestPOST,requestGET} from "@/utils/request.js";
export default { export default {
getShopInfo(){ getShopInfo() {
return requestPOST(`${process.env.OLSHOP_URL}/shop/get_shop_info`) return requestPOST(`${process.env.OLSHOP_URL}/shop/get_shop_info`);
} },
} getWxMiniSubscribeMessageConfig() {
return requestPOST(
`${process.env.OLSHOP_URL}/shop/getWxMiniSubscribeMessageConfig`
);
}
};
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
import spokesman from "@/api/spokesman.js"; import spokesman from "@/api/spokesman.js";
import shop from "@/api/shop.js";
import { serialize, getQueryVariable, DFSImg } from "@/utils/index"; import { serialize, getQueryVariable, DFSImg } from "@/utils/index";
export default { export default {
data() { data() {
...@@ -141,6 +142,24 @@ export default { ...@@ -141,6 +142,24 @@ export default {
// } // }
// } // }
// }); // });
// 获取小程序开启的订阅消息配置
shop.getWxMiniSubscribeMessageConfig().then(res => {
if (res.data.code == 200) {
const data = res.data.data;
console.log("wx mini subscribe message data: ", data);
if (data != null) {
const subscribeMessageObj = {};
for (var key in data) {
if(data[key] && data[key].template_id) {
subscribeMessageObj[key] = data[key].template_id;
}
}
this.$store.commit("setSubscribeMessageObj", subscribeMessageObj);
}
}
});
}, },
checkLogin() { checkLogin() {
let getOpenid = wx.getStorageSync("openid"); let getOpenid = wx.getStorageSync("openid");
......
...@@ -53,21 +53,20 @@ export default { ...@@ -53,21 +53,20 @@ export default {
payData.success = res => { payData.success = res => {
console.log("支付成功", res, this.options); console.log("支付成功", res, this.options);
// TODO 小程序订阅消息埋点
const orderSn = this.options.orderSn; const orderSn = this.options.orderSn;
try { try {
wx.requestSubscribeMessage({ if (this.$store.state.subscribeMessageObj && Object.keys(this.$store.state.subscribeMessageObj).length > 0) {
      tmplIds: [ // TODO 小程序订阅消息埋点
        '10xLnJqIXoMx4Cqb8Q_oC6cD4aKqU4pAu3_lSDNRILA', wx.requestSubscribeMessage({
'X4W6WgC-Mq58SUwUwsCOIORDFFYfZFR0uFcafxgXBls'       tmplIds: Object.values(this.$store.state.subscribeMessageObj),
      ],
      success(res) {       success(res) {
        console.log("message success response: ", res);         console.log("message success response: ", res);
      },       },
fail(res) { fail(res) {
        console.log("message fail response: ", res)         console.log("message fail response: ", res)
      }       }
    })      })
}
} catch (err) { } catch (err) {
console.error("subscribeMessage-err", err); console.error("subscribeMessage-err", err);
} }
......
const mutations = { const mutations = {
setSpokesman(state, obj) { setSpokesman(state, obj) {
for (let [key, val] of Object.entries(obj)) { for (let [key, val] of Object.entries(obj)) {
state[key] = val; state[key] = val;
}
} }
} },
setSubscribeMessageObj(state, subscribeMessageObj) {
state.subscribeMessageObj = subscribeMessageObj;
}
};
export default mutations export default mutations
\ No newline at end of file
const state={ const state = {
spokesmanGroupId:"", spokesmanGroupId: "",
spokesmanShopId:"", spokesmanShopId: "",
spokesmanRelId:"" spokesmanRelId: "",
} subscribeMessageObj: {}
};
export default state export default state
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment