示例#1
0
def accountBalance(uToken, studentCode):
    '''
    查询指定学员的高思币和余额,用于支付页面调用
    :param uToken:
    :param studentCode:
    :return:
    '''
    '''初始化数据'''
    url = conf["domain_test"] + conf["account_balance"]
    '''传参'''
    p = {"StudentCode": studentCode}
    sign = getSign.getSign(uToken, params=p)
    h = {"sign": sign, "uToken": uToken, "partner": "10016"}
    '''发送请求'''
    resp = requests.get(url=url, params=p, headers=h)
    r = resp.json()
    '''查询成功返回响应'''

    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("查询金库信息失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" +
              r["Message"])
    else:
        return r
示例#2
0
def addShoppingCart(host,uToken,studentCode,classCodes,isPromoted):
    '''
    添加班级到指定学员的购物车中,不允许重复添加
    :param uToken:
    :param studentCode:
    :param classCodes:
    :param isPromoted:
    :return:
    '''

    '''初始化数据'''
    url = host + conf["add_shopping_cart"]

    '''传参'''
    d = {"StudentCode": studentCode,
        "ClassCodes": classCodes,
        "IsPromoted": isPromoted
        }
    sign = getSign.getSign(uToken, data = d)
    h = {"sign": sign, "partner": "10016", "Content-Type": "application/json;charset=utf-8", "uToken":uToken }

    '''发送请求'''
    resp = requests.post(url = url, data = json.dumps(d), headers = h)  #添加购物车
    r = resp.json()

    '''添加成功返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("添加购物车失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        print(str(classCodes) + "已成功添加购物车")
        return r
示例#3
0
def removeShoppingCart(host,uToken,studentCode,classCodes):
    '''
    移除购物车,把班级从学员的购物车中移除
    :param uToken:
    :param studentCode:
    :param classCodes:
    :return:
    '''

    '''初始化数据'''
    url = host + conf["remove_shopping_cart"]

    '''传参'''
    d = {"StudentCode": studentCode,
        "ClassCodes": classCodes,
        }
    sign = getSign.getSign(uToken, data = d)
    h = {"sign": sign, "partner": "10016", "Content-Type": "application/json;charset=utf-8", "uToken":uToken }

    '''发送请求'''
    resp = requests.post(url = url, data = json.dumps(d), headers = h)  #移除购物车
    r = resp.json()

    '''移除成功返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("移除购物车失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        print(str(classCodes) + "已成功移除购物车")
        return r
示例#4
0
def cancelOrder(host, uToken, studentCode, orderCode):
    '''
    取消订单
    :param uToken:
    :param studentCode:
    :param orderCode:
    :return:
    '''
    '''初始化数据'''
    url = host + conf["cancel_order"]
    '''传参'''
    d = {
        "StudentCode": studentCode,
        "OrderCode": orderCode,
    }

    sign = getSign.getSign(uToken, data=d)
    h = {
        "sign": sign,
        "partner": "10016",
        "Content-Type": "application/json;charset=utf-8",
        "uToken": uToken
    }
    '''发送请求'''
    resp = requests.post(url=url, data=json.dumps(d), headers=h)
    r = resp.json()
    '''取消后返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("取消订单失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        print("订单[" + orderCode + "]取消成功")

    return r
示例#5
0
def shoppingCartList(host ,uToken,studentCode):
    '''
    获取指定学员的购物车内班级列表
    :param uToken:
    :param studentCode:
    :return:
    '''

    '''初始化数据'''
    url = host + conf["shopping_cart_list"]

    '''传参'''
    p = {"StudentCode": studentCode}
    sign = getSign.getSign(uToken, params = p)
    h = {"sign": sign, "partner": "10016", "Content-Type": "application/json;charset=utf-8", "uToken": uToken}

    '''发送请求'''
    resp = requests.get(url=url, params=p, headers=h)  # 计算优惠
    r = resp.json()

    '''选课单获取成功返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("选课单获取失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        print("选课单获取成功:")
        for classes in r["AppendData"]["Items"]:
            sem = semester[classes["Items"][0]["Semester"]]
            print("有效课程" +": "+str(classes["Items"][0]["Name"])+" "+str(classes["Items"][0]["Code"]))
            for parts in classes["Items"][0]["Items"]:
                if parts["Enable"] == True:
                    check = "√"
                else:
                    check = "×"
                if parts["Purchased"] == True :
                     price = '已购买'
                else:
                    price = str(round(parts["Price"]))
                if parts["StartLessonNo"] == parts["EndLessonNo"]:
                    print("     "+ check +sem +"-"+ parts["Section"]+":"+"第"+str(parts["StartLessonNo"])+"次课")
                else:
                    print("     "+ check +sem +"-"+ parts["Section"]+":"+
                          "第" +str(parts["StartLessonNo"]) + "-"+ str(parts["EndLessonNo"]) +"次课:¥"+price )
        for classes in r["AppendData"]["InvalidItems"]:
            print("失效课程" + ": " + str(classes["Name"]) + " " + str(classes["Code"]))

        return r
示例#6
0
def placeOrder(host, uToken, studentCode, goldCoinAmount, accountBalanceAmount,
               items):
    """
    提交订单,并返回订单编号和应付金额
    :param uToken:
    :param studentCode:
    :param goldCoinAmount: 高思币
    :param accountBalanceAmount: 余额
    :param items: 课程信息
    :return:
    """
    '''初始化数据'''
    url = host + conf["place_order"]
    '''传参'''
    d = {
        "StudentCode": studentCode,
        "Channel": 6,
        "Items": items,
        "GoldCoinAmount": goldCoinAmount,
        "AccountBalanceAmount": accountBalanceAmount
    }

    sign = getSign.getSign(uToken, data=d)
    h = {
        "sign": sign,
        "partner": "10016",
        "Content-Type": "application/json;charset=utf-8",
        "uToken": uToken
    }
    '''发送请求'''
    resp = requests.post(url=url, data=json.dumps(d), headers=h)
    r = resp.json()
    '''提交后返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("提交订单失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        if r["AppendData"]["AmountPayable"] != 0.0:
            print("订单[" + r["AppendData"]["OrderCode"] + "]提交成功,需付款¥" +
                  str(round(r["AppendData"]["AmountPayable"])) + ",等待付款...")
            r["IsPaid"] = False
        else:
            print("订单[" + r["AppendData"]["OrderCode"] + "]提交成功,付款金额¥0,购买成功!")
            r["IsPaid"] = True
    return r
示例#7
0
def alipayAppPaymentParamesters(host,uToken,orderCode):
    '''

    :param orderCode:
    :return:
    '''
    '''初始化'''
    url = host + conf["alipay_app_payment_paramesters"]

    '''传参'''
    p = {"orderCode":orderCode,"appId":"2016091901925114"}
    sign = getSign.getSign(uToken, params=p)
    h = {"sign": sign, "partner": "10016", "Content-Type": "application/json;charset=utf-8", "uToken": uToken}

    '''发送请求'''
    resp = requests.get(url=url, params=p, headers=h)
    r = resp.json()
    print(r["AppendData"])

    return r
示例#8
0
def loginByPassword(phone, password):
    '''密码登录'''
    '''初始化数据'''
    url = conf["domain_test"] + conf["login_by_password"]
    '''传参'''
    d = {"Phone": phone, "Password": password}
    sign = getSign.getSign(data=d)
    h = {
        "sign": sign,
        "partner": "10016",
        "Content-Type": "application/json;charset=utf-8"
    }
    '''发送请求'''
    resp = requests.post(url=url, data=json.dumps(d), headers=h)
    r = resp.json()
    '''登录成功返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("登录失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        for stu in r["AppendData"]:
            print("学员 [" + stu["Name"] + "] 登录成功")
        return r
示例#9
0
def calcPrice(host,
              uToken,
              items,
              studentCode,
              goidCoin=None,
              balance=None,
              choosedCoupon=False,
              selectedCouponIds=None):
    '''
    计算报名指定班级的价格和享受的优惠,可以使用优惠劵
    :param uToken:token
    :param items: 班级信息
    :param studentCode: 学生编码
    :param choosedCoupon: 选择优惠券 默认未选择
    :param selectedCouponIds:优惠券编码 选填项
    :return: 响应数据
    '''
    '''初始化数据'''
    url = host + conf["calc_price"]
    '''传参'''
    d = {
        "StudentCode": studentCode,
        "Channel": 6,
        "ChoosedCoupon": False,
        "Items": items
    }
    if choosedCoupon == True and selectedCouponIds != None:
        d["ChoosedCoupon"] = True
        d["SelectedCouponIds"] = selectedCouponIds
    elif choosedCoupon == True and selectedCouponIds != None:
        print("计算价格参数有误!")

    sign = getSign.getSign(uToken, data=d)
    h = {
        "sign": sign,
        "partner": "10016",
        "Content-Type": "application/json;charset=utf-8",
        "uToken": uToken
    }
    '''发送请求'''
    resp = requests.post(url=url, data=json.dumps(d), headers=h)  # 计算优惠
    r = resp.json()
    '''计算后返回响应'''
    try:
        assert r["ResultType"] == 0
    except AssertionError:
        print("计算价格失败,错误类型:" + str(r["ResultType"]) + ",错误信息:" + r["Message"])
    else:
        print("计算价格成功:")
        print("课程信息:")
        print("-")
        for class_iterator in r["AppendData"]["Items"]:
            sem = semester[class_iterator["Semester"]]

            print(class_iterator["ClassName"] + " " +
                  class_iterator["ClassCode"])
            for part_iterator in class_iterator["Items"]:
                print("     " + sem + part_iterator["Section"] + ": ¥" +
                      str(round(part_iterator["Price"])))
            if class_iterator["ManageFee"] != 0.0:
                print("管理费:¥" + str(class_iterator["ManageFee"]))
            if class_iterator["Deposit"] != 0.0:
                print("押金:¥" + str(class_iterator["Deposit"]))
            if class_iterator["Coupons"] != []:
                print("班级优惠明细:")
                for coupon_iterator in class_iterator["Coupons"]:
                    print("     " + coupon_iterator["CouponPolicyName"] +
                          ":¥" + str(round(coupon_iterator["Amount"])))
            print("-")
        print("结算明细:")
        print("课程总数:" + str(r["AppendData"]["ClassNum"]) + "个")
        print("课程费用:¥" + str(round(r["AppendData"]["TotalPrice"])))
        if r["AppendData"]["TotalDeposit"] != 0.0:
            print("总押金¥:" + str(r["AppendData"]["TotalDeposit"]))
        if r["AppendData"]["TotalManageFee"] != 0.0:
            print("总管理费:¥" + str(r["AppendData"]["TotalManageFee"]))
        if not r["AppendData"]["MemberCoupons"] is None:
            print(r["AppendData"]["MemberCoupons"]["CouponPolicy"] + ":¥" +
                  str(round(r["AppendData"]["MemberCoupons"]["Amount"])))
            for items_iterator in r["AppendData"]["MemberCoupons"]["Items"]:
                print("     " + items_iterator["CouponPolicyName"] + ":¥" +
                      str(round(items_iterator["Amount"])))
        if not r["AppendData"]["CDAndSysCoupons"] is None:
            print(r["AppendData"]["CDAndSysCoupons"]["CouponPolicy"] + ":¥" +
                  str(round(r["AppendData"]["CDAndSysCoupons"]["Amount"])))
            for items_iterator in r["AppendData"]["CDAndSysCoupons"]["Items"]:
                print("     " + items_iterator["CouponPolicyName"] + ":¥" +
                      str(round(items_iterator["Amount"])))
        print("优惠券:" + r["AppendData"]["CouponUsedStatus"]["Tips"] + ":¥" +
              str(round(r["AppendData"]["CouponUsedStatus"]["Amount"])))
        g = min(
            r["AppendData"]["MaxGoldCoinAmount"], goidCoin,
            r["AppendData"]["TotalPrice"] -
            r["AppendData"]["CouponUsedStatus"]["Amount"])
        if goidCoin != 0.00 and r["AppendData"]["TotalPrice"] - r[
                "AppendData"]["CouponUsedStatus"]["Amount"] > 0:
            print("高思币:共" + str(int(goidCoin)) + "个,本次使用" + str(int(g)))
        if balance != 0.00:
            print("余额:¥" + str(balance))
        price = r["AppendData"]["AmountPayable"] - g - balance
        print("合计:¥" + str(round(price)))
        return r