위 챗 애플 릿 설정 - 서버 nodejs 버 전
2528 단어 js
1. 여기 서 제 가 말씀 드 리 고 싶 은 것 은 서버 와 상호작용 을 하 는 것 과 관련 이 있다 면 서버 도 메 인 이름 은 https 프로 토 콜 을 지원 해 야 합 니 다.아 리 운 과 텐 센트 운 에 서 는 https 인증 서 를 무료 로 신청 할 수 있다.저 는 텐 센트 클 라 우 드 를 사 용 했 습 니 다. 작업 절차 링크: 텐 센트 와 https 신청 입 니 다.
2. 서버 쪽 https 요청 설정 코드 는 다음 과 같 습 니 다. 저 는 koa2web 엔 드 프레임 워 크 (추천) 를 사용 합 니 다.
const koa = require('koa');
const path = require('path');
const webstatic = require('koa-static');
const fs = require('fs');
const enforceHttps = require('koa-sslify');
const http = require('http');
const https = require('https');
const router = require(path.join(__dirname, 'router', './router.js')).router;
//
const staticPath = path.join(__dirname, 'static');
const staticConf = webstatic(staticPath);
const app = new koa();
app.use(enforceHttps({
trustProtoHeader: false
}));
app.use(staticConf);
메시지 푸 시 서버 설정
1. token 을 작성 한 후 제출 을 클릭 하면 자동 으로 서버 url 주 소 를 방문 합 니 다. 따라서 요청 주 소 를 미리 설정 하여 get 요청 을 해 야 합 니 다.
2. 검사 방식 은 sha 1 입 니 다. sha 1 모듈 을 설치 해 야 합 니 다. 서명 검사 에 실패 하면 매개 변수 이름 대신 값 을 사전 순서 로 정렬 하 는 지 확인 하 십시오. 구체 적 인 코드 는 다음 과 같 습 니 다.
// nginx
const options = {
key: fs.readFileSync(path.join(__dirname, 'ssls', 'XX.key')),
cert: fs.readFileSync(path.join(__dirname, 'ssls', 'XX.crt'))
};
router(app);
http.createServer(app.callback()).listen(80);
https.createServer(options, app.callback()).listen(443);
/**
* @version 1.0
*
*/
const path = require('path');
const util = require(path.join(__dirname, '../', 'util.js')).Util;
const wechatLanuch = (ctx) => {
console.log(' ');
let param = ctx.query;
console.log(' ');
console.log(param);
if (param) {
let sign = param.signature;
let very = [param.timestamp, param.nonce];
let verySign = util.encodeData(very);
//
console.log(verySign);
console.log(sign);
if (sign == verySign) {
ctx.response.body = param.echostr;
console.log(' ');
} else {
ctx.response.body = { 'msg': 'vaild error' };
}
}
};
module.exports = { wechatLanuch };
이상 은 주의 점 입 니 다. 기본 설정 이 끝나 면 애플 릿 을 즐겁게 개발 할 수 있 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[2022.04.19] 자바스크립트 this - 생성자 함수와 이벤트리스너에서의 this18일에 this에 대해 공부하면서 적었던 일반적인 함수나 객체에서의 this가 아닌 오늘은 이벤트리스너와 생성자 함수 안에서의 this를 살펴보기로 했다. new 키워드를 붙여 함수를 생성자로 사용할 때 this는...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.