From 978222bd407f8484f139201abaeb90acfc89a52c Mon Sep 17 00:00:00 2001 From: Changlon Date: Mon, 24 Jan 2022 15:32:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=B7=BB=E5=8A=A0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=B7=BB=E5=8A=A0=5F=5Ftests=5F=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/common.ts | 15 --------------- example/index.ts | 39 +++++++++++++++++++++++++++++++++++++++ example/oauth.ts | 23 ----------------------- example/send.ts | 44 -------------------------------------------- 4 files changed, 39 insertions(+), 82 deletions(-) delete mode 100644 example/common.ts create mode 100644 example/index.ts delete mode 100644 example/oauth.ts delete mode 100644 example/send.ts diff --git a/example/common.ts b/example/common.ts deleted file mode 100644 index 6eeb52e..0000000 --- a/example/common.ts +++ /dev/null @@ -1,15 +0,0 @@ -const koa = require('koa') -const Router = require('koa-router') -const wechat = require('../src/lib/wechat').default -const app_ = new koa() -const wapp_ = new wechat({ - appId:"wx3ace0c0fa2f4cab0", - appSecret:"8ea32e13460637765fb65a5e48b7c023" -}) -const router_ = new Router() - -module.exports = { - app:app_, - wapp:wapp_, - router:router_ -} \ No newline at end of file diff --git a/example/index.ts b/example/index.ts new file mode 100644 index 0000000..2f1689e --- /dev/null +++ b/example/index.ts @@ -0,0 +1,39 @@ + +import koa from 'koa' +import koaRouter from 'koa-router' +import koaXmlBody from 'koa-xml-body' +import WechatApplication from "../src/lib/wechat" + +const weapp = new WechatApplication({ + appId:"wx3ace0c0fa2f4cab0", + appSecret:"8ea32e13460637765fb65a5e48b7c023", + token:"changlon" +}) + +var OPENID +weapp.text("debug",async acc =>{ + OPENID = acc.fromUser + acc.send.sendTxtMsg("debuging...") +}) + +const Service = new koa() +const Router = new koaRouter() + + +Router.all(`/wechat_debug`,weapp.start()) +Router.all(`/debug`,async (ctx,next)=>{ + const debugFuncName = ctx.query.func || "pushTxtCustomerMsg" + const openid = ctx.query.openid + const content = ctx.query.content + console.log(debugFuncName,openid,content) + const debugTarget = weapp[`${debugFuncName}`] + const res = await debugTarget(openid,content) + console.log(res) +}) + + +Service.use(koaXmlBody()) +Service.use(Router.routes()) +Service.listen(3001) + + diff --git a/example/oauth.ts b/example/oauth.ts deleted file mode 100644 index 04f5d16..0000000 --- a/example/oauth.ts +++ /dev/null @@ -1,23 +0,0 @@ - -const { - app, - wapp, - router -} = require('./common') - -const xmlParser = require ('koa-xml-body') - -wapp.oauth(async function handler(data,ctx) { - const openid = data.openid - ctx.response.redirect('http://www.baidu.com?openid='+openid) -}) - -router.all('/wechat_dev',wapp.start()) - -router.get('/MP_verify_Mi8hQs3epYmV9Q5G.txt',async ctx =>{ - ctx.body = `授权凭证` -}) - -app.use(xmlParser()) -app.use(router.routes()) -app.listen(3001) diff --git a/example/send.ts b/example/send.ts deleted file mode 100644 index 3b15e87..0000000 --- a/example/send.ts +++ /dev/null @@ -1,44 +0,0 @@ -const xmlP = require('koa-xml-body') - -const { - app:ap, - wapp:wap, - router:rt -} = require('./common') - - -wap.text('text',async acc =>{ - await acc.send.sendTxtMsg("Text") - await acc.send.pushTxtCustomerMsg(acc.fromUser,"pushText") - console.log(acc.context.accessTokenCache) - - setTimeout(async ()=>{ - for(let i = 0;i<1;i++) { - - const res = await acc.send.pushTemplateMsg(acc.fromUser,"z607o0lv86kSOUtudqAszoAW8HOcmV3ZjFu7JDwCjDE",{ - title:{ - value:"支付提醒", - color:"#173177" - }, - content:{ - value:"续费vip享8折优惠", - color:"#173117" - } - },"http://www.baidu.com",{ - // appid:"wx67c3a8e87ca5bae0", - // pagepath:"pages/index/index" - }) - - console.log(res) - } - - },3000) - -}) - -rt.all("/wechat_dev",wap.start()) - - -ap.use(xmlP()) -ap.use(rt.routes()) -ap.listen(3001)