无敌技术网
无敌技术网
致力于网络资源共享
90后 狮子座 联系

控制台新建一个nodejs12.16 的云函数粘贴下方代码即可


"use strict";
const request = require("request")


exports.main_handler = async (event, context, callback) => {
//代码开始  


//输出日志
console.log(event)

//发送Token验证
if(event.httpMethod === 'GET')
{

return {
        "isBase64Encoded": false,
        "statusCode": 200,
        "headers": {"Content-Type":"plain/text"},
        "body": event.queryString.echostr
    }

}



//截取信息
var str = event.body;

var fromuser = str.match(/<FromUserName><!\[CDATA\[(\S*)\]\]/)[1];
var touser = str.match(/<ToUserName><!\[CDATA\[(\S*)\]\]/)[1];
var type = str.match(/<MsgType><!\[CDATA\[(\S*)\]\]/)[1];
var text = str.match(/<Content><!\[CDATA\[(\S*)\]\]/)[1];






//信息卡片
var card ="<xml><ToUserName><![CDATA["+fromuser+"]]></ToUserName>\n<FromUserName><![CDATA["+touser+"]]></FromUserName>\n<CreateTime>1601906834</CreateTime>\n<MsgType><![CDATA[text]]></MsgType>\n<Content><![CDATA["+text+"]]></Content>\n<MsgId>23076956945465193</MsgId>\n</xml>"


//回复信息
return {
        "isBase64Encoded": false,
        "statusCode": 200,
        "headers": {"Content-Type":"plain/text"},
        "body": card
    }


//代码结束
};
	


ps:API网关触发记得勾上启用集成响应
声明:若无特殊注明,本文为《无敌技术网》原创,转载请保留文章出处。