10
10
from linkv_sdk .http .http import http
11
11
12
12
13
+ class OrderType (object ):
14
+ __slots__ = ['idx' ]
15
+
16
+ def __init__ (self , idx ):
17
+ self .idx = idx
18
+
19
+ def string (self ):
20
+ return str (self .idx )
21
+
22
+
23
+ class PlatformType (object ):
24
+ __slots__ = ['value' ]
25
+
26
+ def __init__ (self , value ):
27
+ self .value = value
28
+
29
+ def string (self ):
30
+ return self .value
31
+
32
+
33
+ OrderAdd = OrderType (1 )
34
+ OrderDel = OrderType (2 )
35
+
36
+ PlatformH5 = PlatformType ('h5' )
37
+ PlatformANDROID = PlatformType ('android' )
38
+ PlatformIOS = PlatformType ('ios' )
39
+
40
+
13
41
class Live (object ):
14
42
def __init__ (self ):
15
43
pass
@@ -75,12 +103,12 @@ def SuccessOrderByLiveOpenID(live_open_id, unique_id, order_type, gold, money, e
75
103
'app_id' : config ().app_key ,
76
104
'uid' : live_open_id ,
77
105
'request_id' : unique_id ,
78
- 'type' : str ( order_type ),
106
+ 'type' : order_type . string ( ),
79
107
'value' : str (gold ),
80
108
'money' : str (money ),
81
109
'expriation' : str (time .mktime (datetime .now ().timetuple ()) + expr * 86400 ),
82
110
'channel' : config ().alias ,
83
- 'platform' : platform_type ,
111
+ 'platform' : platform_type . string () ,
84
112
}
85
113
86
114
if len (order_id ) > 0 :
@@ -119,7 +147,7 @@ def ChangeGoldByLiveOpenID(live_open_id, unique_id, order_type, gold, expr, opti
119
147
'app_id' : config ().app_key ,
120
148
'uid' : live_open_id ,
121
149
'request_id' : unique_id ,
122
- 'type' : str ( order_type ),
150
+ 'type' : order_type . string ( ),
123
151
'value' : str (gold ),
124
152
}
125
153
if expr > 0 :
@@ -142,7 +170,10 @@ def ChangeGoldByLiveOpenID(live_open_id, unique_id, order_type, gold, expr, opti
142
170
143
171
result = json .loads (response .read ())
144
172
145
- return int (result ['status' ]) == 200
173
+ return {
174
+ 'status' : False ,
175
+ 'ok' : int (result ['status' ]) == 200 ,
176
+ }
146
177
147
178
@staticmethod
148
179
def GetGoldByLiveOpenID (live_open_id ):
@@ -199,22 +230,21 @@ def GetGoldByLiveOpenID(self, live_open_id):
199
230
200
231
201
232
def genRandomString ():
202
- container = '' . join ( random . sample ( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , 8 ))
203
- container += str ( int ( time . mktime ( datetime . now (). timetuple ())))
204
- container += '' . join ( random . sample ( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , 8 ))
205
- return container
233
+ return '{}{}{}' . format (
234
+ '' . join ( random . sample ( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , 8 )),
235
+ str ( int ( time . mktime ( datetime . now (). timetuple ()))),
236
+ '' . join ( random . sample ( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , 8 )))
206
237
207
238
208
239
def genSign (params , md5_secret ):
209
240
data = __encode (params ) + "&key=" + md5_secret
210
241
obj = hashlib .new ('md5' )
211
- obj .update (data )
242
+ obj .update (data . decode ( encoding = 'utf8' ) )
212
243
return obj .hexdigest ().lower ()
213
244
214
245
215
246
def __encode (params ):
216
- keys = params .keys ()
217
- keys .sort ()
247
+ keys = sorted (params .keys ())
218
248
container = ''
219
249
for k in keys :
220
250
if len (container ) > 0 :
0 commit comments