You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package main
import (
"WechatGateWay/global"
"WechatGateWay/handle"
"WechatGateWay/third_part"
"fmt"
"github.com/robfig/cron"
"github.com/spf13/viper"
"log"
"net/http"
"os"
)
func init ( ) {
// 读取配置文件
workDir , _ := os . Getwd ( )
viper . SetConfigName ( "application" )
viper . SetConfigType ( "yml" )
viper . AddConfigPath ( workDir )
err := viper . ReadInConfig ( )
if err != nil {
fmt . Println ( "config file not found" )
os . Exit ( 1 )
}
global . WechatCorpId = viper . GetString ( "wechat.CorpId" )
global . WechatToken = viper . GetString ( "wechat.AppToken" )
global . WechatEncodingAesKey = viper . GetString ( "wechat.EncodingAesKey" )
global . WechatSendSecret = viper . GetString ( "wechat.SendSecret" )
global . WechatSendAid = viper . GetString ( "wechat.SendAid" )
// receive_id 企业应用的回调, 表示corpid
global . WxCrypt = global . NewWXBizMsgCrypt ( global . WechatToken , global . WechatEncodingAesKey , global . WechatCorpId , global . XmlType )
third_part . GetRemoteToken ( )
log . Println ( "server init success" )
}
func main ( ) {
c := cron . New ( )
//每30分钟执行一次
c . AddFunc ( "0 */30 * * * *" , func ( ) { go third_part . GetRemoteToken ( ) } )
c . Start ( )
log . Println ( "任务注册成功" )
// 开启一个http服务器, 接收来自企业微信的消息
http . HandleFunc ( "/" , handle . HandleTencent )
port := viper . GetString ( "server.port" )
if port == "" {
port = "8080"
}
log . Println ( "server start at port:" , port )
log . Fatalln ( http . ListenAndServe ( ":" + port , nil ) )
}