Commit dec1aeff authored by 任国军's avatar 任国军

add transferCustomerService

parent 1d732172
Pipeline #22613 passed with stage
in 3 seconds
'use strict'; 'use strict';
const xml2js = require('xml2js');
const Controller = require('egg').Controller; const Controller = require('egg').Controller;
class TestController extends Controller { class TestController extends Controller {
async test() { async test() {
const { service, ctx } = this; this.ctx.set('content-type', 'text/xml');
const from = { lng: 120.069206, lat: 30.291121 }; const data = {
const to = { lng: 120.212997, lat: 30.29133 }; MsgType: 'transfer_customer_service',
const ret = await service.course.lbs.getLBSDistance('walking', from, [ to, to ]); ToUserName: 'to',
ctx.success(ret); FromUserName: 'from',
CreateTime: parseInt(new Date() / 1000),
};
const builder = new xml2js.Builder();
const xml = builder.buildObject(data);
this.ctx.body = xml;
console.log(this.ctx);
} }
} }
module.exports = TestController; module.exports = TestController;
...@@ -124,6 +124,7 @@ class UserService extends Service { ...@@ -124,6 +124,7 @@ class UserService extends Service {
if (ctx.isEmpty(userInfo)) { if (ctx.isEmpty(userInfo)) {
const uuid = uuidV4(); const uuid = uuidV4();
userInfo = await ctx.classModel.V5.CourseUser.findOrCreate({ where: { openid, is_deleted: 0 }, defaults: { uuid, openid } }); userInfo = await ctx.classModel.V5.CourseUser.findOrCreate({ where: { openid, is_deleted: 0 }, defaults: { uuid, openid } });
userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { openid, is_deleted: 0 } });
} }
// 存储缓存标识 // 存储缓存标识
...@@ -138,7 +139,6 @@ class UserService extends Service { ...@@ -138,7 +139,6 @@ class UserService extends Service {
await app.memcache.set(key, value, 7 * 24 * 3600); await app.memcache.set(key, value, 7 * 24 * 3600);
const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid }); const authToken = await this.service.jwt.apply({ user_uuid: userInfo.uuid, openid: userInfo.openid });
await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken, 7 * 24 * 3600); await app.memcache.set('course_auth_token_' + userInfo.uuid, authToken, 7 * 24 * 3600);
JSON.s;
const ret = { const ret = {
user_uuid: userInfo.uuid, user_uuid: userInfo.uuid,
openid: userInfo.openid, openid: userInfo.openid,
......
...@@ -5,6 +5,7 @@ const SECRET = 'a1b2d32b018988176181497bd74a0b7d'; ...@@ -5,6 +5,7 @@ const SECRET = 'a1b2d32b018988176181497bd74a0b7d';
const fs = require('fs'); const fs = require('fs');
const request = require('request'); const request = require('request');
const crypto = require('crypto'); const crypto = require('crypto');
const xml2js = require('xml2js');
class WechatService extends Service { class WechatService extends Service {
async getAccessToken() { async getAccessToken() {
...@@ -49,12 +50,16 @@ class WechatService extends Service { ...@@ -49,12 +50,16 @@ class WechatService extends Service {
} }
if (!flag) { if (!flag) {
return { this.ctx.set('content-type', 'text/xml');
let xml = {
MsgType: 'transfer_customer_service', MsgType: 'transfer_customer_service',
ToUserName: data.FromUserName, ToUserName: data.FromUserName,
FromUserName: data.ToUserName, FromUserName: data.ToUserName,
CreateTime: parseInt(new Date() / 1000), CreateTime: parseInt(new Date() / 1000),
}; };
const builder = new xml2js.Builder();
xml = builder.buildObject(xml);
this.ctx.body = xml;
} }
return; return;
} }
......
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