def saveCid(self): try: cid = self.jsonBody['cid'] platform = self.jsonBody['platform'] logger.debug('cid: %s, platform: %s', cid, platform) userid = self.user['_id'] # userid = '5a016819ca71430a9d0fe108' logger.debug('userid: %s', userid) push_cid_obj = ClassHelper('PushCid').find_one({'userid': userid}) print push_cid_obj push_cid = MeObject('PushCid', obj=push_cid_obj) print type(push_cid) push_cid['userid'] = userid push_cid['platform'] = platform push_cid['cid'] = cid push_cid['logout'] = False push_cid.save() self.write(ERR_SUCCESS.message) r = ClassHelper('PushCid').db.update_many('PushCid', { 'cid': cid, 'userid': { '$ne': userid }, 'logout': False }, {'$set': { 'logout': True }}) logger.debug('r:%s', r) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def createUserInviteCode(self): cursor = ClassHelper('User').find({}) if cursor: i = 0 for u in cursor: code = ClassHelper('InviteCode').find_one({'from': u['_id'], 'status': 0}) n = 0 if not code: while (True): try: invite_code = MeObject('InviteCode') invite_code['code'] = InviteCodeUtil.create_code() invite_code['status'] = 0 invite_code['from'] = u['_id'] invite_code.save() n = n + 1 logger.debug('create invite code success') self.notify_new_code(u['_id']) # logger.debug('create invite code finish %d', i) if n >= 1: break except Exception, e: logger.error(e) else: logger.debug('user already has a code') i = i + 1 logger.debug('finish %d', i) logger.debug('all finish')
def saveCid(self): try: cid = self.jsonBody['cid'] platform = self.jsonBody['platform'] logger.debug('cid: %s, type: %s', cid, type) userid = self.user['_id'] logger.debug('userid: %s', userid) push_cid_obj = ClassHelper('PushCid').find_one({'userid': userid}) print push_cid_obj push_cid = MeObject('PushCid', obj=push_cid_obj) # if push_cid is None: # push_cid = MeObject('PushCid') # else: # push_cid = Me print type(push_cid) push_cid['userid'] = userid push_cid['platform'] = platform push_cid['cid'] = cid push_cid.save() self.write(ERR_SUCCESS.message) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def create(self): price_config = MeObject('PriceConfig') price = self.get_argument('price', 1) price_config['price'] = int(price) price_config.save() # logger.debug('') self.write(ERR_SUCCESS.message)
def save_login_log(self, userid): try: client = self.request.headers.get("X-MeCloud-Client", None) ip = self.request.remote_ip device = self.request.headers.get("X-MeCloud-Device", None) platform = self.request.headers.get("X-MeCloud-Platform", None) system = self.request.headers.get("X-MeCloud-System", None) channel = self.request.headers.get("X-MeCloud-Channel", None) location_lon = self.request.headers.get("X-MeCloud-Location-Lon", None) location_lat = self.request.headers.get("X-MeCloud-Location-Lat", None) print 'client, ip, device, platform, system, channel, lon, lat ', client, ip, device, platform, system, channel, location_lon, location_lat ll = MeObject('LoginLog') ll['user'] = userid if client: ll['client'] = client if ip: ll['ip'] = ip if device: ll['device'] = device if platform: ll['platform'] = platform if system: ll['system'] = system if channel: ll['channel'] = channel if location_lon and location_lat: ll['location'] = {'lon': location_lon, 'lat': location_lat} ll.save() except Exception, e: print e msg = traceback.format_exc() print msg
def createAlipayAppOrder(self): print self.jsonBody obj = self.jsonBody coin_setting_id = obj.get('id') # coinSettingId # channel = obj.get('channel', '') # version = obj.get('version', '') channel = self.request.headers.get("X-MeCloud-Channel", None) version = self.request.headers.get("X-MeCloud-Client", None) log.debug('coin_setting_id: %s', coin_setting_id) coin_setting = MeObject('CoinSetting').get(coin_setting_id) log.debug('coin_setting: %s', coin_setting) if coin_setting is None: # 未找到充值条目 self.write(ERR_PARA.message) return out_trade_no = self.createOrderNo() log.debug('out_trade_no: %s', out_trade_no) if BaseConfig.mode == 'online': total_fee = coin_setting['price'] else: total_fee = 0.01 # 这里将金额设为1分钱,方便测试 body = '黑密虚拟商品-黑密滴' + str(coin_setting['amount']) + '个' subject = '黑密滴' payment_info = self.make_payment_info(out_trade_no=out_trade_no, subject=subject, total_amount=total_fee, body=body) log.debug('payment_info:%s', payment_info) res = alipay_core.make_payment_request(payment_info) result = {} result['code'] = 0 result['errCode'] = 0 result['res'] = res # result['res']='xxxx' log.debug('res:%s', res) log.debug('result res:%s', result['res']) # 创建充值流水记录 rf = MeObject('RechargeFlow') rf['user'] = self.user['_id'] rf['recharge'] = coin_setting['price'] rf['amount'] = coin_setting['amount'] rf['os'] = coin_setting['os'] rf['platform'] = 0 # 支付宝APP if channel: rf['channel'] = channel rf['version'] = version rf['status'] = 0 rf['orderNo'] = out_trade_no rf['order'] = '' rf.save() self.write(result)
def createWxAppOrder(self): logger.debug(self.jsonBody) obj = self.jsonBody coin_setting_id = obj.get('id') # coinSettingId channel = obj.get('channel', '') version = obj.get('version', '') logger.debug('coin_setting_id: %s', coin_setting_id) coin_setting = MeObject('CoinSetting').get(coin_setting_id) logger.debug('coin_setting: %s', coin_setting) if coin_setting is None: # 未找到充值条目 self.write(ERR_PAY_NOT_FIND_COIN_SETTING.message) return out_trade_no = PayUtil.createOrderNo() logger.debug('out_trade_no: %s', out_trade_no) pub = UnifiedOrder_pub() pub.parameters['out_trade_no'] = out_trade_no # 设置参数自己的订单号 pub.parameters['body'] = '黑密虚拟商品-黑密滴' + str( coin_setting['amount']) + '个' # 设置商品描述 pub.parameters['total_fee'] = str(coin_setting['price']) # 设置总金额 pub.parameters['notify_url'] = WxPayConf_pub.NOTIFY_URL # 设置回调url pub.parameters['trade_type'] = 'APP' # 支付类型,固定为app wx_result = pub.getResult() logger.info('wx create order result: %s', wx_result) if wx_result['return_code'] == 'SUCCESS': logger.debug('prepay_id: %s', wx_result['prepay_id']) result = {} result['code'] = 0 result['prepayid'] = wx_result['prepay_id'] result['appid'] = wx_result['appid'] result['partnerid'] = wx_result['mch_id'] # 商户号 # 创建充值流水记录 rf = MeObject('RechargeFlow') rf['user'] = self.user['_id'] rf['recharge'] = coin_setting['price'] rf['amount'] = coin_setting['amount'] rf['os'] = coin_setting['os'] rf['platform'] = 1 # 微信APP if channel: rf['channel'] = channel rf['version'] = version rf['status'] = 0 rf['orderNo'] = out_trade_no rf['order'] = '' rf.save() self.write(result) else: self.write(ERR_PAY_CREATE_ORDERN0_ERROR.message)
def createAlbumConfig(self): for d in DetectClass.list: o = MeObject('AlbumConfig') o['id'] = d['id'] o['name'] = d['name'] o['title'] = '' o['weight'] = 0 o['show'] = False for ud in DetectClass.list_use: if d['id'] == ud['id']: o['title'] = ud['title'] o['show'] = True break o.save() self.write(ERR_SUCCESS.message)
def createCommentSession(self): cursor = ClassHelper('Message').find({'msg_type': 2}) if cursor: i = 1 for d in cursor: m = MeObject('Message', obj=d) logger.debug('message id :%s', m['_id']) logger.debug('fromid:%s toid:%s', m['from_id'], m['to_id']) session = SessionUtil.create(m['from_id'], m['to_id']) logger.debug('session:%s', session) m['session'] = session m.save() logger.debug('%d finish', i) i = i + 1 # break logger.debug('all finish')
def notify_new_code(self, userid): # 长链接通知 title = '恭喜获得了一枚新的黑蜜邀请码' content = '快分享给朋友一起来玩吧' uri = 'honey://newInviteCode' message_dict = {'t': 'notify'} message_dict['title'] = title message_dict['subtitle'] = content message_dict['avatar'] = None message_dict['to_id'] = userid message_dict['uri'] = uri message_json = json.dumps(message_dict, ensure_ascii=False) logger.debug('publish_message:%s', message_json) rc = RedisDb.get_connection() publish_result = rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json) logger.debug('publish_result: %s', publish_result) push_cid_obj = ClassHelper('PushCid').find_one({'userid': userid}) logger.debug('push_cid_obj: %s', push_cid_obj) if (push_cid_obj is None) or push_cid_obj['logout'] is True: # 没有找到对应的push_cid self.write(ERR_PARA.message) return push_cid = MeObject('PushCid', obj=push_cid_obj) result = MyGtUtil.pushMessageToSingle(push_cid['cid'], title.decode("utf-8"), content.decode("utf-8"), data=uri) logger.debug('push result:%s', result)
def createInviteCode(self): count = int(self.get_argument('count', 1)) if count > 100: count = 100 i = 0 while (True): try: invite_code = MeObject('InviteCode') invite_code['code'] = InviteCodeUtil.create_code() invite_code['status'] = 0 invite_code.save() i = i + 1 logger.debug('create invite code finish %d', i) if i >= count: break except Exception, e: logger.error(e)
def post(self, action=None): try: logger.debug('Cookie: %s', self.request.headers['Cookie']) cookie = self.request.headers['Cookie'].split('"')[1] RedisDb.delete(cookie) self.clear_cookie('u') push_cid_obj = ClassHelper('PushCid').find_one( {'userid': self.user['_id']}) if push_cid_obj: push_cid = MeObject('PushCid', obj=push_cid_obj) push_cid['logout'] = True push_cid.save() self.write(ERR_SUCCESS.message) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_INVALID.message)
def push(self): try: userid = self.jsonBody['userid'] otherid = self.jsonBody['otherid'] action = self.jsonBody.get('action') logger.debug('userid: %s, otherid: %s, action: %s', userid, otherid, action) if userid is None or action is None or otherid is None: self.write(ERR_PARA.message) return uri = action_uri_dict.get(action, None) if uri is None: self.write(ERR_PARA.message) return uri = 'honey://' + uri logger.debug('uri: %s', uri) if action == 'claimed': uri = uri + '/' + otherid notify_content = self.getNotifyContent(action, otherid) logger.debug('notify_content: %s', notify_content) if notify_content is None: self.write(ERR_PARA.message) return # 长链接通知 message_dict = {'t': 'notify'} message_dict['title1'] = notify_content['title'] # message_dict['title2'] = notify_content['title2'] message_dict['title2'] = notify_content['content'] message_dict['to_id'] = userid message_dict['uri'] = uri message_json = json.dumps(message_dict, ensure_ascii=False) logger.debug(message_json) rc = RedisDb.get_connection() publish_result = rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json) logger.debug('public_result: %s', publish_result) push_cid_obj = ClassHelper('PushCid').find_one({'userid': userid}) logger.debug('push_cid_obj: %s', push_cid_obj) if push_cid_obj is None: # 没有找到对应的push_cid self.write(ERR_PARA.message) return push_cid = MeObject('PushCid', obj=push_cid_obj) result = MyGtUtil.pushMessageToSingle( push_cid['cid'], notify_content['title'].decode("utf-8"), notify_content['content'].decode("utf-8"), data=uri) logger.debug('result:%s', result) # result = PushUtil.pushMessageToSingle() self.write(result) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def createInviteCode(self): count = int(self.get_argument('count', 1)) if count > 100: count = 100 i = 0 list = [] while (True): try: invite_code = MeObject('InviteCode') invite_code['code'] = InviteCodeUtil.create_code() invite_code['status'] = 0 invite_code.save() list.append(invite_code['code']) i = i + 1 print 'create invite code finish ', i if i >= count: break except Exception, e: print e
def createAlipayAppOrder(self): logger.debug(self.jsonBody) obj = self.jsonBody coin_setting_id = obj.get('id') # coinSettingId channel = obj.get('channel', '') version = obj.get('version', '') logger.debug('coin_setting_id: %s', coin_setting_id) coin_setting = MeObject('CoinSetting').get(coin_setting_id) logger.debug('coin_setting: %s', coin_setting) if coin_setting is None: # 未找到充值条目 self.write(ERR_PAY_NOT_FIND_COIN_SETTING.message) return out_trade_no = PayUtil.createOrderNo() logger.debug('out_trade_no: %s', out_trade_no) total_fee = 0.01 # 这里将金额设为1分钱,方便测试 body = '黑密虚拟商品-黑密滴' + str(coin_setting['amount']) + '个' subject = '黑密滴' payment_info = self.make_payment_info(out_trade_no=out_trade_no, subject=subject, total_amount=total_fee, body=body) res = alipay_core.make_payment_request(payment_info) result = {} result['code'] = 0 result['res'] = res print res # 创建充值流水记录 rf = MeObject('RechargeFlow') rf['user'] = self.user['_id'] rf['recharge'] = coin_setting['price'] rf['amount'] = coin_setting['amount'] rf['os'] = coin_setting['os'] rf['platform'] = 0 # 支付宝APP if channel: rf['channel'] = channel rf['version'] = version rf['status'] = 0 rf['orderNo'] = out_trade_no rf['order'] = '' rf.save() self.write(result)
def activate(self): logger.debug('invite code activate start ') code = self.jsonBody.get('code') device = self.jsonBody.get('device') invite_code = ClassHelper('InviteCode').find_one({'code': code, 'status': 0}) logger.debug('jsonBody:%s', self.jsonBody) if not invite_code: logger.debug('invite code error') result = deepcopy(ERR_PARA.message) result['errMsg'] = '邀请码错误' result['msg'] = 'invite code error' self.write(result) return else: active_device = MeObject('ActiveDevice') active_device['device'] = device active_device['code'] = code try: active_device.save() invite_code_obj = MeObject('InviteCode', obj=invite_code) invite_code_obj['status'] = 1 # invite_code_obj['to'] = self.user['_id'] invite_code_obj.save() logger.debug('success') self.write(ERR_SUCCESS.message) return except Exception, e: logger.debug('device already active') logger.error(e) msg = traceback.format_exc() logger.error(msg) result = deepcopy(ERR_DEVICE_ALREADY_ACTIVE.message) result['errMsg'] = '设备已激活,不能重复激活' result['msg'] = 'device already active' self.write(result) return
def push(self): try: userid = self.jsonBody['userid'] otherid = self.jsonBody['otherid'] action = self.jsonBody.get('action') extra = self.jsonBody.get('extra', '') logger.debug('third push userid: %s, otherid: %s, action: %s', userid, otherid, action) if userid is None or action is None or otherid is None: self.write(ERR_PARA.message) return uri = action_uri_dict.get(action, None) if uri is None: self.write(ERR_PARA.message) return uri = 'honey://' + uri logger.debug('uri: %s', uri) if action == 'claimed' or action == 'newFeed': uri = uri + '/' + otherid elif action == 'similarFace' or action == 'intrestedFace': uri = uri + '?unreadCount=' + extra notify_content = self.getNotifyContent(action, userid, otherid, extra) logger.debug('notify_content: %s', notify_content) if notify_content is None: self.write(ERR_PARA.message) return # 长链接通知 message_dict = {'t': 'notify'} message_dict['title'] = notify_content['title'] # message_dict['title2'] = notify_content['title2'] message_dict['subtitle'] = notify_content['content'] message_dict['avatar'] = notify_content['avatar'] message_dict['to_id'] = userid message_dict['uri'] = uri message_json = json.dumps(message_dict, ensure_ascii=False) logger.debug('publish_message:%s', message_json) rc = RedisDb.get_connection() publish_result = rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json) logger.debug('publish_result: %s', publish_result) push_cid_obj = ClassHelper('PushCid').find_one({'userid': userid}) logger.debug('push_cid_obj: %s', push_cid_obj) if (push_cid_obj is None) or push_cid_obj['logout'] is True: # 没有找到对应的push_cid self.write(ERR_PARA.message) return claim_count = 0 message_count = 0 stat1 = ClassHelper('StatCount').find_one( {'name': 'toClaim_' + userid}) # logger.debug('stat1:') if stat1: claim_count = stat1['count'] if claim_count < 0: claim_count = 0 stat2 = ClassHelper('StatCount').find_one( {'name': 'unreadMsg_' + userid}) if stat2: message_count = stat2['count'] if message_count < 0: message_count = 0 badge = claim_count + message_count push_cid = MeObject('PushCid', obj=push_cid_obj) result = MyGtUtil.pushMessageToSingle( push_cid['cid'], notify_content['title'].decode("utf-8"), notify_content['content'].decode("utf-8"), uri, badge) logger.debug('result:%s', result) # result = PushUtil.pushMessageToSingle() self.write(result) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def loginWithoutPwd(self): obj = json.loads(self.request.body) if not checkKeys(obj, ['username']): self.write(ERR_PARA.message) return user = MeUser(self.appName, obj) userHelper = ClassHelper('develop', 'User') userInfo = userHelper.get(self.appInfo['user']) # library授权 if userInfo['type'] == 2: if user['bundleId']: log.info("Library User[%s] Auth. bundleId[%s]", user['username'], user['bundleId']) elif user['package']: log.info("Library User[%s] Auth. package[%s]", user['username'], user['package']) log.info('auth app[%s]', self.appInfo['appName']) # 普通授权失败 elif user['bundleId'] != None: if (not self.appInfo.has_key('bundleId') ) or self.appInfo['bundleId'] != user['bundleId']: log.err('[%s] bundleId[%s] not match. LoginWithoutPwd Error.', self.appInfo['appName'], user['bundleId']) self.write(ERR_UNAUTHORIZED.message) return log.info('auth app[%s]', self.appInfo['appName']) elif user['package']: if (not self.appInfo.has_key('package') ) or self.appInfo['package'] != user['package']: log.err('[%s] package[%s] not match. LoginWithoutPwd Error.', self.appInfo['appName'], user['package']) self.write(ERR_UNAUTHORIZED.message) return log.info('auth app[%s]', self.appInfo['appName']) else: log.err("loginWithoutPwd Error: Invalid. %s", self.request.body) self.write(ERR_UNAUTHORIZED.message) return # 检查数量限制 # userHelper = ClassHelper(self.appDb, "User") # userUpper = self.appInfo['userUpper'] # # userUpper=0表示无数量限制 # if userUpper>0: # if userHelper.count() > userUpper: # log.err('[%s] over user count limit', self.appInfo['appName']); # self.write(ERR_USER_PERMISSION.message) try: user.loginWithoutPwd() log.info('LoginWithoutPwd: %s', user['username']) self.set_secure_cookie("u", user['username']) user['authen'] = userInfo['authen'] self.write(json.dumps(user, cls=MeEncoder)) # 登录日志 loginLog = MeObject(self.appName, 'LoginLog') loginLog['username'] = user['username'] if hasattr(self, 'client_ip'): loginLog['ip'] = self.client_ip loginLog.save() except Exception, e: log.err("LoginWithoutPwd Error: %s Error:%s", self.request.body, str(e)) self.write(str(e))
def send(self): try: logger.debug(self.jsonBody) obj = self.jsonBody logger.debug('to_id:' + obj.get('to_id')) logger.debug('c: %s', obj.get('c')) logger.debug('c_type: %s', obj.get('c_type')) logger.debug('m_id: %s', obj.get('m_id')) media_id = obj.get('m_id') from_id = self.user['_id'] logger.debug('from_id: %s', from_id) user_query = MeQuery("UserInfo") user_info = user_query.find_one({'user': from_id}) message_dict = { 'from_id': from_id, 'c': obj.get('c'), 'to_id': obj.get('to_id'), 'c_type': obj.get('c_type'), 'msg_type': 2, 'from_avatar': user_info['avatar'], 'from_name': user_info['nickName'], 'status': 0, 'm_id': media_id } message = MeObject('Message', obj=message_dict) message['session'] = SessionUtil.create(from_id, obj.get('to_id')) message.save() # 格式化时间为long型 message_dict['create_at'] = long( message['createAt'].strftime('%s')) * 1000 message_dict['t'] = 'comment' message_dict['id'] = message['_id'] message_json = json.dumps(message_dict, ensure_ascii=False) logger.debug(message_json) print type(message['createAt']) rc = RedisDb.get_connection() rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json) # 发push push_cid_obj = ClassHelper('PushCid').find_one( {'userid': obj.get('to_id')}) logger.debug('push_cid_obj: %s', push_cid_obj) if push_cid_obj and (push_cid_obj['logout'] is False): # push_cid = MeObject('PushCid', obj=push_cid_obj) title = user_info['nickName'] content = obj.get('c') content = PushEmoji.getPushContent(content) data = 'honey://comment/' + from_id + '?m_id=' + media_id print title.encode('utf-8') print content.encode('utf-8') claim_count = 0 message_count = 0 stat1 = ClassHelper('StatCount').find_one( {'name': 'toClaim_' + obj.get('to_id')}) if stat1: claim_count = stat1['count'] if claim_count < 0: claim_count = 0 stat2 = ClassHelper('StatCount').find_one( {'name': 'unreadMsg_' + obj.get('to_id')}) if stat2: message_count = stat2['count'] if message_count < 0: message_count = 0 badge = claim_count + message_count t = threading.Thread(target=MyGtUtil.pushMessageToSingle, args=( push_cid_obj['cid'], title.encode('utf-8'), content.encode('utf-8'), data, badge, )) t.setDaemon(True) t.start() # logger.debug(ERR_SUCCESS.message) r = {} r['id'] = message['_id'] r['code'] = 0 r['errCode'] = 0 r['create_at'] = message_dict['create_at'] self.write(r) # 计数 unreadMsg +1 logger.debug('update to_id:unreadMsg_%s unreadMsg count ', obj.get('to_id')) ClassHelper('StatCount').updateOne( {'name': 'unreadMsg_' + obj.get('to_id')}, {"$inc": { 'count': 1 }}, upsert=True) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def createConfig(self): o = MeObject('VersionControl') o['settingName'] = 'needCode' o['switch'] = True o['platform'] = 'android' o['version'] = '1.0' o['versionNo'] = 2 o.save() # o = MeObject('VersionControl') # o['settingName'] = 'inReview' # o['switch'] = True # o['platform'] = 'android' # o['version'] = '1' # o.save() # # o = MeObject('VersionControl') # o['settingName'] = 'wxPay' # o['switch'] = True # o['platform'] = 'ios' # o['version'] = '1' # o.save() # o = MeObject('VersionControl') # o['settingName'] = 'wxPay' # o['switch'] = True # o['platform'] = 'android' # o['version'] = '1' # o.save() # # o = MeObject('VersionControl') # o['settingName'] = 'extra' # o['switch'] = True # o['platform'] = 'ios' # o['version'] = '1' # o.save() # o = MeObject('VersionControl') # o['settingName'] = 'extra' # o['switch'] = True # o['platform'] = 'android' # o['version'] = '1' # o.save() # # o = MeObject('VersionControl') # o['settingName'] = 'applePay' # o['switch'] = True # o['platform'] = 'ios' # o['version'] = '1' # o.save() # o = MeObject('VersionControl') # o['settingName'] = 'applePay' # o['switch'] = True # o['platform'] = 'android' # o['version'] = '1' # o.save() # # o = MeObject('VersionControl') # o['settingName'] = 'showIncome' # o['switch'] = True # o['platform'] = 'ios' # o['version'] = '1' # o.save() # o = MeObject('VersionControl') # o['settingName'] = 'showIncome' # o['switch'] = True # o['platform'] = 'android' # o['version'] = '1' # o.save() self.write(ERR_SUCCESS.message)
def send(self): try: logger.debug(self.jsonBody) obj = self.jsonBody logger.debug('to_id:' + obj.get('to_id')) logger.debug('c: %s', obj.get('c')) logger.debug('c_type: %s', obj.get('c_type')) logger.debug('m_id: %s', obj.get('m_id')) media_id = obj.get('m_id') from_id = self.user['_id'] logger.debug('from_id: %s', from_id) user_query = MeQuery("UserInfo") user_info = user_query.find_one({'user': from_id}) message_dict = { 'from_id': from_id, 'c': obj.get('c'), 'to_id': obj.get('to_id'), 'c_type': obj.get('c_type'), 'msg_type': 2, 'from_avatar': user_info['avatar'], 'from_name': user_info['nickName'], 'status': 0, 'm_id': media_id } message = MeObject('Message', obj=message_dict) message.save() # 格式化时间为long型 message_dict['create_at'] = long( message['createAt'].strftime('%s')) * 1000 message_dict['t'] = 'comment' message_dict['id'] = message['_id'] message_json = json.dumps(message_dict, ensure_ascii=False) logger.debug(message_json) print type(message['createAt']) rc = RedisDb.get_connection() rc.publish(Constants.REDIS_CHANNEL_FOR_PUSH, message_json) # 发push push_cid_obj = ClassHelper('PushCid').find_one( {'userid': obj.get('to_id')}) logger.debug('push_cid_obj: %s', push_cid_obj) if push_cid_obj: # push_cid = MeObject('PushCid', obj=push_cid_obj) title = user_info['nickName'] content = '新评论' data = 'honey://comment/' + from_id + '?m_id=' + media_id print title.encode('utf-8') print content.encode('utf-8') t = threading.Thread(target=MyGtUtil.pushMessageToSingle, args=( push_cid_obj['cid'], title.encode('utf-8'), content.encode('utf-8'), data, )) t.setDaemon(True) t.start() # logger.debug(ERR_SUCCESS.message) r = {} r['id'] = message['_id'] r['code'] = 0 r['create_at'] = message_dict['create_at'] self.write(r) except Exception, e: logger.error(e) msg = traceback.format_exc() logger.error(msg) self.write(ERR_PARA.message)
def createWxAppOrder(self): log.debug('in create wx app order json body:%s', self.jsonBody) obj = self.jsonBody coin_setting_id = obj.get('id') # coinSettingId # channel = obj.get('channel', '') # version = obj.get('version', '') try: channel = self.request.headers.get("X-MeCloud-Channel", None) version = self.request.headers.get("X-MeCloud-Client", None) except: pass log.debug('coin_setting_id: %s', coin_setting_id) coin_setting = MeObject('CoinSetting').get(coin_setting_id) log.debug('coin_setting: %s', coin_setting) if coin_setting is None: # 未找到充值条目 self.write(ERR_PARA.message) return out_trade_no = self.createOrderNo() log.debug('out_trade_no: %s', out_trade_no) pub = UnifiedOrder_pub() pub.parameters['out_trade_no'] = out_trade_no # 设置参数自己的订单号 pub.parameters['body'] = '黑蜜虚拟商品-黑蜜滴' + str(coin_setting['amount']) + '个' # 设置商品描述 # pub.parameters['total_fee'] = str(coin_setting['price']) # 设置总金额 if BaseConfig.mode == 'online': pub.parameters['total_fee'] = str(coin_setting['price'] * 100) else: pub.parameters['total_fee'] = '1' # 设置总金额 1分用于测试 pub.parameters['notify_url'] = WxPayConf_pub.NOTIFY_URL # 设置回调url if BaseConfig.mode == 'online': pub.parameters['notify_url'] = WxPayConf_pub.NOTIFY_URL_RELEASE pub.parameters['trade_type'] = 'APP' # 支付类型,固定为app wx_result = pub.getResult() log.info('wx create order result: %s', wx_result) if wx_result['return_code'] == 'SUCCESS': log.debug('prepay_id: %s', wx_result['prepay_id']) result = {} result['code'] = 0 result['errCode'] = 0 result['prepayid'] = wx_result['prepay_id'] result['appid'] = wx_result['appid'] result['partnerid'] = wx_result['mch_id'] # 商户号 result['package'] = 'Sign=WXPay' result['noncestr'] = out_trade_no result['timestamp'] = str(int(time.time())) client_pub = UnifiedOrder_pub() client_pub.parameters['prepayid'] = result['prepayid'] client_pub.parameters['appid'] = result['appid'] client_pub.parameters['partnerid'] = result['partnerid'] client_pub.parameters['package'] = result['package'] client_pub.parameters['noncestr'] = result['noncestr'] client_pub.parameters['timestamp'] = result['timestamp'] client_sign = client_pub.getSign(client_pub.parameters) result['sign'] = client_sign # 创建充值流水记录 rf = MeObject('RechargeFlow') rf['user'] = self.user['_id'] rf['recharge'] = coin_setting['price'] rf['amount'] = coin_setting['amount'] rf['os'] = coin_setting['os'] rf['platform'] = 1 # 微信APP if channel: rf['channel'] = channel rf['version'] = version rf['status'] = 0 rf['orderNo'] = out_trade_no rf['order'] = '' rf.save() self.write(result) else: self.write(ERR_PARA.message)