...
This commit is contained in:
parent
7df54a521c
commit
ab915d0a41
@ -41,49 +41,37 @@ class Telegram {
|
||||
@PostMapping("webhook")
|
||||
fun test(@RequestBody str : String) {
|
||||
println("path >>> $str")
|
||||
// val client = WebClient.create()
|
||||
// client.get()
|
||||
// .uri("https://api.telegram.org/${globalEvv.telegramBotKey}/getUpdates")
|
||||
// .retrieve()
|
||||
// .bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
|
||||
}
|
||||
|
||||
// @ResponseBody
|
||||
// @GetMapping("webhook")
|
||||
// fun test(@PathVariable path : String) {
|
||||
// println("path >>> $path")
|
||||
// val client = WebClient.create()
|
||||
// client.get()
|
||||
// .uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/getUpdates")
|
||||
// .retrieve()
|
||||
// .bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
@Bean
|
||||
@Scheduled(cron = "0 0 0/1 * * *") //
|
||||
fun runJob() {
|
||||
try {
|
||||
println("telegramBotKey >>>> ${globalEvv.telegramBotKey}")
|
||||
println("telegramMyId >>>> ${globalEvv.telegramMyId}")
|
||||
println("weatherApiKey >>>> ${globalEvv.weatherApiKey}")
|
||||
if (globalEvv.weatherApiKey?.length ?: 0 > 3 && globalEvv.telegramBotKey?.length ?: 0 > 3 && globalEvv.telegramMyId?.length ?: 0 > 3) {
|
||||
logService.log("telegramBotKey >>>> ${globalEvv.telegramBotKey}")
|
||||
logService.log("telegramMyId >>>> ${globalEvv.telegramMyId}")
|
||||
logService.log("weatherApiKey >>>> ${globalEvv.weatherApiKey}")
|
||||
if (
|
||||
((globalEvv.weatherApiKey?.length ?: 0) > 3) &&
|
||||
((globalEvv.telegramBotKey?.length ?: 0) > 3) &&
|
||||
((globalEvv.telegramMyId?.length ?: 0) > 3)
|
||||
) {
|
||||
val client0 = WebClient.create()
|
||||
val result = client0.get()
|
||||
.uri("http://api.weatherapi.com/v1/current.json?key=${globalEvv.weatherApiKey}&q=seoul&aqi=no")
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java)
|
||||
.block() ?: "FAIL"
|
||||
var sss = Gson().fromJson<CurrentWeather>(result, CurrentWeather::class.java)
|
||||
|
||||
Gson().fromJson(result, CurrentWeather::class.java)?.let { sss ->
|
||||
val client = WebClient.create()
|
||||
client.get()
|
||||
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=온도${sss.current?.temp_c}")
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
}
|
||||
}
|
||||
}catch (e : Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@ -95,31 +83,35 @@ class Telegram {
|
||||
@Scheduled(cron = "0 0/2 * * * *") //
|
||||
fun pollingTelegramUpdate() {
|
||||
try {
|
||||
println("pollingTelegramUpdate telegramBotKey >>>> ${globalEvv.telegramBotKey}")
|
||||
println("pollingTelegramUpdate telegramMyId >>>> ${globalEvv.telegramMyId}")
|
||||
println("pollingTelegramUpdate weatherApiKey >>>> ${globalEvv.weatherApiKey}")
|
||||
if (globalEvv.weatherApiKey?.length ?: 0 > 3 && globalEvv.telegramBotKey?.length ?: 0 > 3 && globalEvv.telegramMyId?.length ?: 0 > 3) {
|
||||
logService.log("pollingTelegramUpdate telegramBotKey >>>> ${globalEvv.telegramBotKey}")
|
||||
logService.log("pollingTelegramUpdate telegramMyId >>>> ${globalEvv.telegramMyId}")
|
||||
logService.log("pollingTelegramUpdate weatherApiKey >>>> ${globalEvv.weatherApiKey}")
|
||||
if (
|
||||
((globalEvv.weatherApiKey?.length ?: 0) > 3 )&&
|
||||
((globalEvv.telegramBotKey?.length ?: 0) > 3 )&&
|
||||
((globalEvv.telegramMyId?.length ?: 0) > 3)
|
||||
) {
|
||||
val client0 = WebClient.create()
|
||||
val result = client0.get()
|
||||
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/getUpdates")
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
println("pollingTelegramUpdate result >>>> $result")
|
||||
var sss = Gson().fromJson<TelegramUpdate>(result, TelegramUpdate::class.java)
|
||||
println("pollingTelegramUpdate sss >>>> $sss")
|
||||
logService.log("pollingTelegramUpdate result >>>> $result")
|
||||
Gson().fromJson(result, TelegramUpdate::class.java)?.let { sss ->
|
||||
logService.log("pollingTelegramUpdate sss >>>> $sss")
|
||||
if (sss.isSucces()) {
|
||||
sss.result?.filter {
|
||||
// println("${(it.message?.date ?: 0L).times(1000L) } > ${before5Min()} ${(it.message?.date ?: 0L).times(1000L) - before5Min()} ")
|
||||
((it.message?.date ?: 0L) * 1000L) > before5Min()
|
||||
}?.forEach {
|
||||
println("pollingTelegramUpdate before Query doOnSuccess m >>>> ${it}")
|
||||
logService.log("pollingTelegramUpdate before Query doOnSuccess m >>>> ${it}")
|
||||
it.message?.let { msg ->
|
||||
println("pollingTelegramUpdate before Query doOnSuccess m >>>> ${msg.message_id}")
|
||||
logService.log("pollingTelegramUpdate before Query doOnSuccess m >>>> ${msg.message_id}")
|
||||
qns(msg.message_id,msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (e : Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@ -128,7 +120,7 @@ class Telegram {
|
||||
fun qns(it : String, msg : Message) {
|
||||
var doSave = true
|
||||
telegramService.findById(it)?.subscribe( { m ->
|
||||
println("pollingTelegramUpdate doOnSuccess m >>>> $m")
|
||||
logService.log("pollingTelegramUpdate doOnSuccess m >>>> $m")
|
||||
if (m != null) {
|
||||
if (msg.text?.contains("어디") == true) {
|
||||
|
||||
@ -143,11 +135,14 @@ class Telegram {
|
||||
},{
|
||||
if (doSave) {
|
||||
telegramService.save(msg)
|
||||
if (msg.text?.contains("어디") == true || msg.text?.startsWith("\"") == true) {
|
||||
sendMsg()
|
||||
}
|
||||
println("pollingTelegramUpdate doOnSuccess comp ")
|
||||
}
|
||||
logService.log("pollingTelegramUpdate doOnSuccess comp")
|
||||
})
|
||||
}
|
||||
|
||||
fun sendMsg() {
|
||||
val client = WebClient.create()
|
||||
client.get()
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
package kr.lunaticbum.back.lun.controllers
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.servlet.ModelAndView
|
||||
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
class User {
|
||||
|
||||
@GetMapping("/join")
|
||||
fun hello(httpServletRequest: HttpServletRequest): ModelAndView {
|
||||
println("onJoin")
|
||||
val vm = ModelAndView()
|
||||
vm.modelMap.put("ddd","asdas")
|
||||
println("${vm.toString()}")
|
||||
return vm
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("joinUser.api")
|
||||
fun joinUser(httpServletRequest: HttpServletRequest, @RequestBody jsonString: String) : String {
|
||||
println("${httpServletRequest.requestURI}")
|
||||
val reqString = jsonString
|
||||
println(reqString)
|
||||
return "1234"
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("test/{path}")
|
||||
fun test(@PathVariable path : String): String {
|
||||
println("path >>> $path")
|
||||
val client = WebClient.create()
|
||||
return client.get()
|
||||
.uri("https://api.telegram.org/bot7934509464:AAE_xUbICxMdywLGnxo7BkeIqA1nVza4P9w/sendMessage?chat_id=71476436&text=${path}")
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package kr.lunaticbum.back.lun.controllers
|
||||
|
||||
import com.google.gson.Gson
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import kr.lunaticbum.back.lun.configs.GlobalEnvironment
|
||||
import kr.lunaticbum.back.lun.model.ResponceResult
|
||||
import kr.lunaticbum.back.lun.model.User
|
||||
import kr.lunaticbum.back.lun.model.UserManager
|
||||
import kr.lunaticbum.back.lun.utils.LogService
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.data.annotation.AccessType
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.servlet.ModelAndView
|
||||
import org.springframework.web.servlet.function.ServerResponse
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
class UserController {
|
||||
|
||||
@Autowired
|
||||
lateinit var globalEvv : GlobalEnvironment
|
||||
|
||||
@Autowired
|
||||
lateinit var logService: LogService
|
||||
|
||||
@Autowired
|
||||
lateinit var userManager: UserManager
|
||||
|
||||
@GetMapping("/join")
|
||||
fun hello(httpServletRequest: HttpServletRequest): ModelAndView {
|
||||
logService.log("onJoin")
|
||||
val vm = ModelAndView()
|
||||
vm.modelMap.put("ddd","asdas")
|
||||
logService.log("${vm.toString()}")
|
||||
return vm
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("joinUser.api")
|
||||
fun joinUser(httpServletRequest: HttpServletRequest, @RequestBody jsonString: String) : ResponseEntity<ResponceResult> {
|
||||
logService.log("${httpServletRequest.requestURI}")
|
||||
logService.log(jsonString)
|
||||
val reqString = jsonString.split("_||L_")
|
||||
var nb = arrayListOf<String>()
|
||||
(reqString[0].replace("_||L_","").split("")).toList().let {
|
||||
nb.addAll(it)
|
||||
}
|
||||
logService.log(nb.toString())
|
||||
var na = arrayListOf<String>()
|
||||
reqString[1].replace("_||L_","").split("").toList().let {
|
||||
na.addAll(it)
|
||||
}
|
||||
|
||||
logService.log(na.toString())
|
||||
var max = nb.size + na.size
|
||||
var fullData = arrayListOf<String>()
|
||||
for (idx in 0..max) {
|
||||
if (idx % 2 == 0) {
|
||||
if (nb.size > 0) {
|
||||
fullData.add(nb.removeLast())
|
||||
}
|
||||
} else {
|
||||
if (na.size > 0) {
|
||||
fullData.add(na.removeLast())
|
||||
}
|
||||
}
|
||||
}
|
||||
logService.log(fullData.joinToString(""))
|
||||
var user = Gson().fromJson(fullData.joinToString(""), User::class.java)
|
||||
var u = userManager.save(user).block()
|
||||
val responce = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(ResponceResult().apply {
|
||||
resultCode = if (u != null) 0 else 8245
|
||||
resultMsg = if (u != null) "OK" else "User Insert Fail"
|
||||
})
|
||||
return responce
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("test/{path}")
|
||||
fun test(@PathVariable path : String): String {
|
||||
logService.log("path >>> $path")
|
||||
val client = WebClient.create()
|
||||
return client.get()
|
||||
.uri("https://api.telegram.org/${globalEvv.telegramBotKey}/sendMessage?chat_id=${globalEvv.telegramMyId}&text=${path}")
|
||||
.retrieve()
|
||||
.bodyToMono(String::class.java).block() ?: "FAIL"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package kr.lunaticbum.back.lun.model
|
||||
|
||||
import lombok.Getter
|
||||
|
||||
|
||||
@Getter
|
||||
class ResponceResult {
|
||||
var resultCode: Int = 0
|
||||
var resultMsg: String? = null
|
||||
}
|
||||
73
src/main/kotlin/kr/lunaticbum/back/lun/model/User.kt
Normal file
73
src/main/kotlin/kr/lunaticbum/back/lun/model/User.kt
Normal file
@ -0,0 +1,73 @@
|
||||
package kr.lunaticbum.back.lun.model
|
||||
|
||||
import kr.lunaticbum.back.lun.utils.LogService
|
||||
import lombok.AllArgsConstructor
|
||||
import lombok.Data
|
||||
import lombok.NoArgsConstructor
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Primary
|
||||
import org.springframework.data.annotation.CreatedDate
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
import org.springframework.data.mongodb.repository.Query
|
||||
import org.springframework.data.mongodb.repository.ReactiveMongoRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
import org.springframework.stereotype.Service
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Document(collection = "User")
|
||||
class User {
|
||||
@Id
|
||||
var user_id: String? = null
|
||||
var user_pw: String? = null
|
||||
var user_pw_check: String? = null
|
||||
|
||||
var user_email: String? = null
|
||||
@CreatedDate
|
||||
var user_join: Long = 0L
|
||||
|
||||
var user_name: String? = null
|
||||
var isAccept : String? = null
|
||||
var isAdmin : String? = null
|
||||
}
|
||||
|
||||
|
||||
@Repository
|
||||
interface UserRepository : ReactiveMongoRepository<User, String> {
|
||||
@Query("{id :?0}")
|
||||
override fun findById(id: String): Mono<User>
|
||||
|
||||
|
||||
fun save(user: User): Mono<User>
|
||||
}
|
||||
interface UserService {
|
||||
fun findById(id: String): Mono<User>?
|
||||
}
|
||||
|
||||
@Service
|
||||
class UserManager : UserService {
|
||||
@Autowired
|
||||
private lateinit var logService: LogService
|
||||
|
||||
@Autowired
|
||||
private lateinit var userRepository: UserRepository
|
||||
|
||||
|
||||
|
||||
override fun findById(id: String): Mono<User>? {
|
||||
return userRepository.findById(id)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun save(user: User): Mono<User> {
|
||||
println("saved user before ${user}")
|
||||
return userRepository.save(user)
|
||||
// .subscribe( { println("saved user after ${it}") },{e -> e.printStackTrace()},{
|
||||
// println("saved user comp")
|
||||
// })
|
||||
}
|
||||
}
|
||||
@ -44,12 +44,13 @@ class Logger {
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class LogService {
|
||||
private val myLogger: Logger? = null
|
||||
|
||||
|
||||
fun logic(id: String) {
|
||||
myLogger?.log("service id = $id")
|
||||
println("service id = $id")
|
||||
}
|
||||
fun log(id: String) {
|
||||
myLogger?.log("log = $id")
|
||||
println("log = $id")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -64,12 +64,19 @@
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function getDivder() {
|
||||
return "_||L_"
|
||||
}
|
||||
function mergeData(a , b) {
|
||||
return a.join("") + getDivder() + b.join("")
|
||||
}
|
||||
|
||||
function userJoin() {
|
||||
var httpRequest;
|
||||
var user_id = document.getElementById("user_id").value;
|
||||
var user_pw = document.getElementById("user_pw").value;
|
||||
var user_pw_check = document.getElementById("user_pw_check").value;
|
||||
if (user_pw === user_pw_check) {
|
||||
var user_email = document.getElementById("user_email").value;
|
||||
var user_birth = document.getElementById("user_birth").value;
|
||||
var user_name = document.getElementById("user_name").value;
|
||||
@ -82,8 +89,10 @@
|
||||
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
||||
if (httpRequest.status === 200) {
|
||||
var result = httpRequest.response;
|
||||
document.getElementById("name").innerText = result.name;
|
||||
document.getElementById("age").innerText = result.age;
|
||||
console.log(result)
|
||||
alert('Request OK!' + result);
|
||||
// document.getElementById("name").innerText = result.name;
|
||||
// document.getElementById("age").innerText = result.age;
|
||||
} else {
|
||||
alert('Request Error!');
|
||||
}
|
||||
@ -91,7 +100,7 @@
|
||||
};
|
||||
/* Get 방식으로 name 파라미터와 함께 요청 */
|
||||
httpRequest.open('POST', 'joinUser.api', true);
|
||||
httpRequest.setRequestHeader("Content-Type", "application/json");
|
||||
httpRequest.setRequestHeader("Content-Type", "text/plain");
|
||||
|
||||
let data = {
|
||||
'user_id': user_id,
|
||||
@ -101,13 +110,18 @@
|
||||
'user_birth': user_birth,
|
||||
'user_name': user_name
|
||||
}
|
||||
|
||||
httpRequest.send(JSON.stringify(data));
|
||||
var odd = []
|
||||
var even = []
|
||||
var dataStr = JSON.stringify(data)
|
||||
var src = dataStr.split("")
|
||||
src.forEach(function (s,i,a) {if (i % 2 === 0) {even.push(s)} else {odd.push(s)}})
|
||||
httpRequest.send(mergeData(even.reverse(),odd.reverse()));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<form >
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><h2>회원가입</h2></td>
|
||||
@ -135,6 +149,6 @@
|
||||
</tr>
|
||||
<tr><td><input type="submit" value="가입하기" class="btn" onclick="userJoin()"></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user