コード例 #1
0
def send_sms(channel, mobile, code, Time):
    ## 获取短息你配置
    conf = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_config")
    [uid, pwd, key] = conf.split(",")

    ## 生成短信内容
    Content = (CONTENT_STR % code).encode("gbk")

    TimeStr = time.strftime("%m%d%H%M%S", time.localtime(Time))
    payload = {
        "userid": uid,
        "pwd": make_pwd(uid, pwd, TimeStr),
        "mobile": str(mobile),
        "content": Content,
        "timestamp": TimeStr
    }

    try:
        r = None
        r = httpc_util.post(SMS_URL, payload)
        rr = json.loads(r.text)

        if rr["result"] == 0:
            return True
    except:
        pass

    print "sms err:", r, channel, payload
    return False
コード例 #2
0
def pre_pay_after_for_yi_zhi_fu(money, channel, pay_channel, data, callback_url):
	AppID = data["appid"]
	MchID = data["mch_id"]
	OrderNo = data["orderno"]
	MchKey = data["mch_key"]
	URL = data["url"]

	## 支付方式选择
	PayType = ""
	if data["pay_type"] == PAY_TYPE_WX_QRCODE:
		PayType = "WX_CODE"
	if data["pay_type"] == PAY_TYPE_WX_WAP:
		PayType = "WX_H5"
	if data["pay_type"] == PAY_TYPE_ZFB_QRCODE:
		PayType = "ALI"
	if data["pay_type"] == PAY_TYPE_ZFB_WAP:
		PayType = "ALI_WAP"

	## 预创建订单成功
	payload = {
		"mchId":MchID,
		"sign":"",
		"body":u"会员充值",
		"outTradeNo":OrderNo,
		"totalFee":"%.2f" % (float(money) / 100),
		"spbillCreateIp":request.remote_addr,
		"notifyUrl":callback_url,
		"tradeType":PayType,
	}
	payload["sign"] = httpc_util.gen_sign(payload, MchKey, lower = False)

	data = httpc_util.post(URL, payload)
	return data.text
コード例 #3
0
def pre_pay_after_for_xin_bao(money, channel, pay_channel, data, callback_url):
	AppID = data["appid"]
	MchID = data["mch_id"]
	OrderNo = data["orderno"]
	MchKey = data["mch_key"]
	URL = data["url"]

	## 支付方式选择
	PayType = ""
	if data["pay_type"] == PAY_TYPE_WX_QRCODE:
		PayType = "0002"
	if data["pay_type"] == PAY_TYPE_WX_WAP:
		PayType = "0004"
	if data["pay_type"] == PAY_TYPE_ZFB_QRCODE:
		PayType = "0003"
	if data["pay_type"] == PAY_TYPE_ZFB_WAP:
		PayType = "0005"

	## 预创建订单成功
	payload = {
		"version":"V1.0",
		"partner_id":MchID,
		"pay_type":PayType,
		"order_no":OrderNo,
		"amount":"%.2f" % (float(money) / 100),
		"notify_url":callback_url,
		"sign":"",
		"summary":u"会员充值",	
	}
	payload["sign"] = httpc_util.gen_sign(payload, MchKey, connect_key = False)

	data = httpc_util.post(URL, payload)
	return data.text
コード例 #4
0
def pre_pay_after_for_wx(money, channel, pay_channel, data, callback_url):
	AppID = data["appid"]
	MchID = data["mch_id"]
	OrderNo = data["orderno"]
	MchKey = data["mch_key"]
	URL = data["url"]

	## 预创建订单成功
	payload = {
		"appid":AppID,
		"mch_id":MchID,
		"nonce_str":md5("%d_%d" % (time_util.now_sec(), rand(1, 99999999))),
		"sign":"",
		"sign_type":"MD5",
		"body":u"会员充值",
		"out_trade_no":OrderNo,
		"total_fee":money,
		"spbill_create_ip":request.remote_addr,
		"notify_url":callback_url,
		"trade_type":"NATIVE",
	}
	payload["sign"] = httpc_util.gen_sign(payload, MchKey, lower = False)
	
	data = httpc_util.post(URL, payload, ctype = "xml")
	if data["return_code"] == "SUCCESS" and data["result_code"] == "SUCCESS":
		path = qrcode_util.qc(data["code_url"])
		return '<html><body><img src="%s" /></body></html>' % path
	elif data["return_code"] == "SUCCESS":
		return jsonify(result = "fail", code = data["err_code"], msg = data["err_code_des"])
	else:
		print data
		return jsonify(result = "fail", msg = "wx err")
コード例 #5
0
def send_sms(channel, phone_number, params, time, nationcode=86):
    ## 获取短息你配置
    conf = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_config")
    [appid, appkey, tpl_id] = conf.split(",")

    now = time
    rand_v = rand(100000, 999999)
    url = "{}?sdkappid={}&random={}".format(URL, appid, rand_v)
    paylaod = {
        "tel": {
            "nationcode": str(nationcode),
            "mobile": str(phone_number)
        },
        "tpl_id": tpl_id,
        "sig": calculate_signature(appkey, rand_v, now, [phone_number]),
        "time": now,
        "params": params,
    }

    try:
        r = None
        r = httpc_util.post(url, paylaod, ctype="json")
        if r["result"] == 0:
            return True
    except:
        pass

    print "sms_err", r, channel, paylaod
    return False
コード例 #6
0
def pre_pay_after_for_bai_fu(money, channel, pay_channel, data, callback_url):
	AppID = data["appid"]
	MchID = data["mch_id"]
	OrderNo = data["orderno"]
	MchKey = data["mch_key"]
	URL = data["url"]

	## 支付方式选择
	PayType = ""
	if data["pay_type"] == PAY_TYPE_WX_QRCODE:
		PayType = "WX"
	if data["pay_type"] == PAY_TYPE_WX_WAP:
		PayType = "WX_WAP"
	if data["pay_type"] == PAY_TYPE_ZFB_QRCODE:
		PayType = "ZFB"
	if data["pay_type"] == PAY_TYPE_ZFB_WAP:
		PayType = "ZFB_WAP"

	## 预创建订单成功
	payload = {
		"merchantNo":MchID,
		"netwayCode":PayType,
		"randomNum":md5(str(rand(1, 99999))),
		"orderNum":OrderNo,
		"payAmount":"%d" % money,
		"goodsName":u"会员充值",
		"callBackUrl":callback_url,
		"callBackUrl":callback_url,
		"requestIP":request.remote_addr,
	}
	src = ",".join(['"%s":"%s"' % (i, payload[i]) for i in sorted(payload.keys())])
	src = "{%s}%s" % (src, MchKey)
	payload["sign"] = md5(src).upper()

	param = {"paramData":json.dumps(payload)}
	data = httpc_util.post(URL, param).json()
	if data["resultCode"] == "00":
		if PayType == "WX" or PayType == "ZFB":
			path = qrcode_util.qc(data["CodeUrl"])
			return '<html><body><img src="%s" /></body></html>' % path
		else:
			return redirect(data["CodeUrl"])
	else:
		print data["resultMsg"]
		return data["resultMsg"]
コード例 #7
0
def get_channel_data():
    rr = httpc_util.post(Config.ADMIN_WEB_SITE + "/api/channel_data", {})
    rr = rr.json()
    for dd in rr["data"]:
        channel = dd["name"]
        channel_id = dd["id"]
        redis_conn.hmset(CHANNEL_CONFIG_TABLE + channel, dd)
        redis_conn.hmset(CHANNEL_CONFIG_TABLE + str(channel_id), dd)
        try:
            redis_conn.hset(WX_CONFIG_TABLE, dd["wx_appid"], dd["wx_token"])
        except:
            pass
        try:
            redis_conn.hset(WX_CONFIG_TABLE, dd["h5_wx_appid"],
                            dd["h5_wx_token"])
        except:
            pass

    return jsonify()
コード例 #8
0
def pre_pay_after_for_mo_mo_fu(money, channel, pay_channel, data, callback_url):
	AppID = data["appid"]
	MchID = data["mch_id"]
	OrderNo = data["orderno"]
	MchKey = data["mch_key"]
	URL = data["url"]

	## 支付方式选择
	PayType = ""
	if data["pay_type"] == PAY_TYPE_WX_QRCODE:
		PayType = "902"
	if data["pay_type"] == PAY_TYPE_WX_WAP:
		PayType = "902"
	if data["pay_type"] == PAY_TYPE_ZFB_QRCODE:
		PayType = "903"
	if data["pay_type"] == PAY_TYPE_ZFB_WAP:
		PayType = "903"

	## 预创建订单成功
	payload = {
		"pay_memberid":int(MchID),
		"pay_orderid":OrderNo,
		"pay_applydate":time_util.formatDateTime(time_util.now_sec()),
		"pay_bankcode":PayType,
		"pay_notifyurl":callback_url,
		"pay_amount":"%.2f" % (float(money) / 100),
	}
	payload["pay_md5sign"] = httpc_util.gen_sign(payload, MchKey, lower = False)
	payload["pay_callbackurl"] = ""
	payload["pay_productname"] = u"会员充值"

	data = httpc_util.post(URL, payload)
	if data.headers['Content-Type'] == 'image/png':
		response = make_response(data.content)
		response.headers['Content-Type'] = 'image/png'
		return response 
	else:
		print data.headers['Content-Type'], data.text
		return data.text
コード例 #9
0
 def post(self, url, data):
     r = httpc_util.post(self.web_site + url, data, ctype = "json")
     return r