@@ -7,32 +7,37 @@ import java.util.concurrent.{CountDownLatch, TimeUnit}
7
7
import com .google .zxing .client .j2se .BufferedImageLuminanceSource
8
8
import com .google .zxing .common .HybridBinarizer
9
9
import com .google .zxing .{BinaryBitmap , DecodeHintType , MultiFormatReader }
10
- import com .typesafe .scalalogging .LazyLogging
11
10
import io .grpc .stub .StreamObserver
12
11
import javax .imageio .ImageIO
13
12
import org .apache .commons .io .IOUtils
13
+ import wechaty .padplus .PuppetPadplus
14
14
import wechaty .padplus .grpc .PadPlusServerOuterClass .{ResponseType , StreamResponse }
15
+ import wechaty .padplus .schemas .GrpcSchemas .GrpcMessagePayload
16
+ import wechaty .padplus .schemas .ModelContact .PadplusContactPayload
15
17
import wechaty .padplus .schemas .ModelUser .ScanData
16
18
import wechaty .padplus .schemas .PadplusEnums .QrcodeStatus
17
- import wechaty .puppet .schemas .Event .EventScanPayload
19
+ import wechaty .puppet .ResourceBox
20
+ import wechaty .puppet .schemas .Contact .ContactGender
21
+ import wechaty .puppet .schemas .Event .{EventLoginPayload , EventMessagePayload , EventScanPayload }
18
22
import wechaty .puppet .schemas .Puppet .{PuppetEventName , isBlank , objectMapper }
19
- import wechaty .puppet .{Puppet , ResourceBox }
20
23
21
24
/**
22
25
*
23
26
* @author <a href="mailto:[email protected] ">Jun Tsai</a>
24
27
* @since 2020-06-21
25
28
*/
26
29
trait GrpcEventSupport extends StreamObserver [StreamResponse ]{
27
- self : GrpcSupport with LocalStoreSupport with Puppet with LazyLogging =>
30
+ self : PuppetPadplus =>
28
31
32
+ protected var selfId : Option [String ] = None
29
33
private val countDownLatch = new CountDownLatch (1 )
30
34
31
35
32
36
protected def awaitStreamStart ()= countDownLatch.await(10 ,TimeUnit .SECONDS )
33
37
override def onNext (response : StreamResponse ): Unit = {
34
38
logger.debug(" stream response:{}" ,response)
35
39
countDownLatch.countDown()
40
+ saveUin(response.getUinBytes)
36
41
37
42
val traceId = response.getTraceId
38
43
if (! isBlank(traceId)){
@@ -66,8 +71,37 @@ trait GrpcEventSupport extends StreamObserver[StreamResponse]{
66
71
payload.qrcode = result.getText
67
72
logger.debug(" Scan QR Code to login: %s\n https://api.qrserver.com/v1/create-qr-code/?data=%s\n " .format(payload.status, payload.qrcode))
68
73
emit(PuppetEventName .SCAN ,payload)
74
+ case ResponseType .MESSAGE_RECEIVE =>
75
+ val rawMessageStr = response.getData()
76
+ val payload = objectMapper.readValue(rawMessageStr,classOf [GrpcMessagePayload ])
77
+ val eventMessagePayload : EventMessagePayload = new EventMessagePayload
78
+ eventMessagePayload.messageId = payload.MsgId
79
+ saveRawMessagePayload(payload.MsgId ,rawMessageStr)
80
+ this .emit(PuppetEventName .MESSAGE , eventMessagePayload)
81
+ case ResponseType .AUTO_LOGIN =>
82
+ logger.debug(" response data:{}" ,response.getData)
83
+ val autoLoginData = objectMapper.readTree(response.getData)
84
+ val wechatUser = autoLoginData.get(" wechatUser" )
85
+
86
+ val rawContactPayload = new PadplusContactPayload
87
+ if (wechatUser.has(" alias" ))
88
+ rawContactPayload.alias= wechatUser.get(" alias" ).asText(" " )
89
+ rawContactPayload.bigHeadUrl = wechatUser.get(" headImgUrl" ).asText()
90
+ rawContactPayload.nickName = wechatUser.get(" nickName" ).asText()
91
+ rawContactPayload.sex = ContactGender .Unknown
92
+ rawContactPayload.userName = wechatUser.get(" userName" ).asText()
93
+ saveRawContactPayload(rawContactPayload.userName,rawContactPayload)
94
+ // "{\"uin\":1213374243,\"online\":true,\"wechatUser\":{\"headImgUrl\":\"http://wx.qlogo.cn/mmhead/ver_1/iag5D2R2U9ibgTW2eh7XUbPTHqpEMP2DhSpXSBeQYzEPWgEmLIx5IDibwicGh4fTh4IibkL4hNianoiaTzXmVORnm1O4ZjhxfPosKzkMPSwic8Iicylk/0\",\"nickName\":\"\351\230\277\350\224\241\",\"uin\":1213374243,\"userName\":\"wxid_gbk03zsepqny22\",\"alias\":\"\",\"verifyFlag\":0}}"
95
+ selfId = Some (rawContactPayload.userName)
96
+
97
+ // val padplusContact = contactSelfInfo()
98
+ // selfId = Some(padplusContact.userName)
99
+ // logger.debug("contactSelf:{}",padplusContact)
100
+ // saveRawContactPayload(padplusContact.userName,padplusContact)
101
+ val eventLoginPayload = new EventLoginPayload
102
+ eventLoginPayload.contactId = rawContactPayload.userName
103
+ emit(PuppetEventName .LOGIN ,eventLoginPayload)
69
104
case _ =>
70
- saveUin(response.getUinBytes)
71
105
// val user = objectMapper.readTree(response.getData())
72
106
// val userName = user.get("userName").asText()
73
107
0 commit comments