示例#1
0
def orderPay():
	resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
	member_info = g.member_info
	req = request.values
	order_sn = req['order_sn'] if 'order_sn' in req else ''
	pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
	target_pay = PayService()
	target_pay.orderSuccess(pay_order_id=pay_order_info.id, params={"pay_sn": ""})
	target_pay.addPayCallbackData(pay_order_id=pay_order_info.id, data=request.data)
	# pay_order_info = PayOrder.query.filter_by( order_sn = order_sn,member_id = member_info.id ).first()
	# if not pay_order_info:
	# 	resp['code'] = -1
	# 	resp['msg'] = "系统繁忙。请稍后再试~~"
	# 	return jsonify(resp)
	# # 用户open_id
	# oauth_bind_info = OauthMemberBind.query.filter_by( member_id =  member_info.id ).first()
	# if not oauth_bind_info:
	# 	resp['code'] = -1
	# 	resp['msg'] = "系统繁忙。请稍后再试~~"
	# 	return jsonify(resp)
	#
	# config_mina = app.config['MINA_APP']
	# notify_url = app.config['APP']['domain'] + config_mina['callback_url']
	#
	# target_wechat = WeChatService( merchant_key=config_mina['paykey'] )
	#
	# data = {
	# 	'appid': config_mina['appid'],
	# 	'mch_id': config_mina['mch_id'],
	# 	'nonce_str': target_wechat.get_nonce_str(),
	# 	'body': '吃吃吃吃',  # 商品描述
	# 	'out_trade_no': pay_order_info.order_sn,  # 商户订单号
	# 	'total_fee': int( pay_order_info.total_price * 100 ),  # 单位是分
	# 	'notify_url': notify_url,
	# 	'trade_type': "JSAPI",
	# 	'openid': oauth_bind_info.openid
	# }
	#
	# pay_info = target_wechat.get_pay_info( pay_data=data)
	#
	# # 保存prepay_id为了后面发模板消息
	# pay_order_info.prepay_id = pay_info['prepay_id']
	# db.session.add( pay_order_info )
	# db.session.commit()
	#
	# resp['data']['pay_info'] = pay_info
	return jsonify(resp)
示例#2
0
def callback():
    logging.info('进入回调函数')
    result_data = {'return_code': 'SUCCESS', 'return_msg': 'OK'}

    header = {'Content-Type': 'application/xml'}
    config_mina = app.config['MINA_APP']

    logging.info(request.data)

    target_wechat = WeChatService(merchant_key=config_mina['paykey'])
    # print(request.data)

    callback_data = target_wechat.xml_to_dict(request.data)

    sign = callback_data['sign']
    callback_data.pop('sign')
    gene_sign = target_wechat.create_sign(callback_data)

    if sign != gene_sign:
        # logging.info('sing!=gene_sign')
        result_data['return_code'] = result_data['return_msg'] = "FAIL"
        return target_wechat.dict_to_xml(result_data), header

    order_sn = callback_data['out_trade_no']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    if not pay_order_info:
        # logging.info('not pay_order_info')
        result_data['return_code'] = result_data['return_msg'] = "FAIL"
        return target_wechat.dict_to_xml(result_data), header

    # if int(pay_order_info.total_price * 100) == int(callback_data['total_fee']):
    #     result_data['return_code'] = result_data['return_msg'] = "FAIL"
    #     return target_wechat.dict_to_xml(result_data), header

    if pay_order_info.status == 1:
        # logging.info('pay_order_info.status == 1')
        return target_wechat.dict_to_xml(result_data), header

    target_pay = PayService()
    target_pay.orderSuccess(pay_order_info.id,
                            params={'pay_sn': callback_data['transaction_id']})

    # 微信回调加入日志
    target_pay.addPayCallbackData(pay_order_id=pay_order_info.id,
                                  data=request.data)

    return target_wechat.dict_to_xml(result_data), header
示例#3
0
def orderCallback():
    """模拟支付"""
    resp = {'code': 0, 'msg': '支付成功', 'data': {}}
    req = request.values
    order_sn = req['order_sn']
    pay_order_info = PayOrder.query.filter_by(order_sn=order_sn).first()
    #模拟第三方支付流水信息,pay_sn
    transaction_id = "1004400740201409030005092168"
    target_pay = PayService()
    order_suc = target_pay.orderSuccess(pay_order_id=pay_order_info.id, params={"pay_sn": transaction_id})
    # 将微信回掉结果放入记录表
    callback = target_pay.addPayCallbackData(pay_order_id=pay_order_info.id, data=pay_order_info)
    if order_suc and callback:
        resp['code'] = 200

    return jsonify(resp)