Example #1
0
def warning_notify(request):
    raw_str = request.body
    logger.info('Warning Notify Wechat Xml Append with Request: %s' % unicode(raw_str))
    wechat_data = xml_to_dict(raw_str)
    parameters = {key.lower(): wechat_data[key] for key in wechat_data}
    # if build_warning_sign(parameters) == wechat_data['AppSignature']:
    send_wechat_warning_notify_mail(wechat_data)
    return HttpResponse('success')
Example #2
0
def warning_notify(request):
    raw_str = request.body
    logger.info('Warning Notify Wechat Xml Append with Request: %s' %
                unicode(raw_str))
    wechat_data = xml_to_dict(raw_str)
    parameters = {key.lower(): wechat_data[key] for key in wechat_data}
    # if build_warning_sign(parameters) == wechat_data['AppSignature']:
    send_wechat_warning_notify_mail(wechat_data)
    return HttpResponse('success')
Example #3
0
def right_notify(request):
    raw_str = request.body
    logger.info('Right Notify Wechat Xml Append with Request: %s' % unicode(raw_str))
    wechat_data = xml_to_dict(raw_str)
    parameters = {key.lower(): wechat_data[key] for key in wechat_data}
    if build_right_sign(parameters) == wechat_data['AppSignature']:
        send_wechat_right_notify_mail(wechat_data)
        return HttpResponse('success')
    else:
        logger.error('Wechat Right Notify Verify Failed!')
        return HttpResponse('error')
Example #4
0
def right_notify(request):
    raw_str = request.body
    logger.info('Right Notify Wechat Xml Append with Request: %s' %
                unicode(raw_str))
    wechat_data = xml_to_dict(raw_str)
    parameters = {key.lower(): wechat_data[key] for key in wechat_data}
    if build_right_sign(parameters) == wechat_data['AppSignature']:
        send_wechat_right_notify_mail(wechat_data)
        return HttpResponse('success')
    else:
        logger.error('Wechat Right Notify Verify Failed!')
        return HttpResponse('error')
Example #5
0
def payment_notify(request):
    params = request.GET
    raw_str = request.body
    if params:
        logger.info('Wechat Verifying Payment for Request: %s' %
                    unicode(params))
        logger.info('Wechat Xml Append with Request: %s' % unicode(raw_str))
        verifyResult = verify_notify(params)
        if verifyResult:
            wechat_data = xml_to_dict(raw_str)
            out_trade_no = params['out_trade_no']
            total_fee = int(params['total_fee'])
            trade_state = params['trade_state']
            logger.info(
                'Wechat Payment Verify Succeeded! The trade state is %s' %
                trade_state)

            if trade_state == '0':
                timestamp = int(time.time())
                parameters = {
                    'openid': wechat_data['OpenId'],
                    'transid': params['transaction_id'],
                    'out_trade_no': out_trade_no,
                    'deliver_timestamp': str(timestamp),
                    'deliver_status': '1',
                    'deliver_msg': 'ok',
                }
                result = deliver_notify(parameters)
                if result['errcode'] == 0:
                    logger.info('Wechat Delivery Notify Succeeded!')
                    payment = Payment.objects.get(payment_no=out_trade_no)
                    payment.confirm(float(total_fee / 100.00))
                    return HttpResponse('success')
                else:
                    logger.error('Wechat Delivery Notify Failed: %s' %
                                 result['errmsg'])
                    return HttpResponse('Delivery Notify Failed!', status=400)
            else:
                logger.error('Trade State != 0')
                return HttpResponse('success')
        else:
            logger.error('Wechat Payment Verify Failed!')
            return HttpResponse('Verify Result Failed', status=400)
    else:
        logger.error('Missing Post Parameters')
        return HttpResponse('Missing Post Parameters', status=400)
Example #6
0
def payment_notify(request):
    params = request.GET
    raw_str = request.body
    if params:
        logger.info('Wechat Verifying Payment for Request: %s' % unicode(params))
        logger.info('Wechat Xml Append with Request: %s' % unicode(raw_str))
        verifyResult = verify_notify(params)
        if verifyResult:
            wechat_data = xml_to_dict(raw_str)
            out_trade_no = params['out_trade_no']
            total_fee = int(params['total_fee'])
            trade_state = params['trade_state']
            logger.info('Wechat Payment Verify Succeeded! The trade state is %s' % trade_state)

            if trade_state == '0':
                timestamp = int(time.time())
                parameters = {
                    'openid': wechat_data['OpenId'],
                    'transid': params['transaction_id'],
                    'out_trade_no': out_trade_no,
                    'deliver_timestamp': str(timestamp),
                    'deliver_status': '1',
                    'deliver_msg': 'ok',
                }
                result = deliver_notify(parameters)
                if result['errcode'] == 0:
                    logger.info('Wechat Delivery Notify Succeeded!')
                    payment = Payment.objects.get(payment_no=out_trade_no)
                    payment.confirm(float(total_fee/100.00))
                    return HttpResponse('success')
                else:
                    logger.error('Wechat Delivery Notify Failed: %s' % result['errmsg'])
                    return HttpResponse('Delivery Notify Failed!', status=400)
            else:
                logger.error('Trade State != 0')
                return HttpResponse('success')
        else:
            logger.error('Wechat Payment Verify Failed!')
            return HttpResponse('Verify Result Failed', status=400)
    else:
        logger.error('Missing Post Parameters')
        return HttpResponse('Missing Post Parameters', status=400)