pay包注释(二)

@login_required()
def to_register(request):
    return render_to_response("pay/register_yeepay.html", context_instance=RequestContext(request))

// 意思简单,就不说了。

打开页面需要填写的表单如下:

此页面使用ajax方式提交:

以上数据被传至process_register处理

@csrf_exempt
@login_required()
def process_register(request):
    # TODO 参数判断
    nick_name = request.POST['nickName']
    real_name = request.POST['realName']
    id_card_type = request.POST['idCardType']
    id_card_no = request.POST['idCardNo']
    mobile = request.POST['mobile']
    email = request.POST['email']
    platform_user_no = UserDetail.objects.get(user=request.user).platform_user_no

  /*  由此句推知,paltform_user_no是在注册时候已经生成了,我们看注册函数

   *  new_user_detail.platform_user_no = random_str(),其中random_str()

   *      

   *  其中random.randint(0,length),在0~length中随机取一个整数,包括length。

   */
    # TODO 权限判断

    yeepay_account = YeepayAccount.objects.get(platform_user_no=platform_user_no)
    yeepay_account.nickname = nick_name
    yeepay_account.real_name = real_name
    yeepay_account.idcard_type = id_card_type
    yeepay_account.idcard_no = id_card_no
    yeepay_account.save()

    # 构造返回参数
    ret_xml, sign, to_url = register(nick_name=nick_name, real_name=real_name, id_card_type=id_card_type,
                                     id_card_no=id_card_no, mobile=mobile, email=email,
                                     platform_user_number=platform_user_no)

 /*调用了register函数,该函数如下:

   

  * 其中sign是签名

  * to_url是易宝注册地址。

  */
    return json_response(True, "0", "success", {"req": ret_xml, 'sign': sign, 'to_url': to_url})

  //返回json数据

成功后易宝回返回callback或者notify,根据返回的类型选择合适的函数。

 

import xml.etree.ElementTree as ET

一个完整的例子就如上。

原文地址:https://www.cnblogs.com/tuifeideyouran/p/3915919.html