Micro-channel Alipay merge to achieve a two-dimensional code to pay

Background note

We are located in a three-city shopping center, having been opened for many years, but benefited from good investment and daily operations, passenger traffic has been relatively stable in the city with the type of project. When the holidays appearances peak traffic periods, due to the efficiency of labor costs, will lead to the backlog of vehicles waiting at the toll gate fee. I was in the parking lot through the exit pinch table estimates, labor costs on average 20-30 seconds to the car. This problem seriously affected the customer's driving experience, so we provide parking online payment function in the Official micro, allowing users to pay in advance online to reach the parking lot of the time without waiting for direct export to leave the car through the exit gates time reduced to an average of 2-3 seconds, significantly increasing traffic efficiency.

Online pre-payment function is implemented H5, 17 years transplanted to the small version of the program. The proportion of users on-line payment of the first month in advance online reached 20%, after a period of operation, this ratio stable at 70%, completely solve the problem of congestion in the parking lot exit.
git log 2017 applet version of the initial submission of
Applet version of the online payment of UI

Since Shangguan only support micro-channel micro-payments (like crap), in order to support some Alipay payment users, and to complement the payment way, the company plans to deploy several payment machines in the parking lot elevator hall. Payment machines using a touch screen floor, since the c / s architecture, the front end is a simple UI presentation, thus practically no performance requirements.

One yards payment

After the design of the payment system in the process, involving the need to support micro-channel payment and Alipay, basic business logic is that users submit the license plate number to the background, the background check to costs generated two-dimensional code with a micro-channel Alipay sdk payment parameters, back again the parameters of the feedback to the payment machines, waits for the user through a micro-channel or pay Alipay client scan two-dimensional code.
Self-service payment machine

In the original first version, in order to support micro-channel and Alipay, we placed on the main interface payment machines, two-dimensional code, the user is prompted to pay with a corresponding app scanning, two-dimensional micro-letter codes were used Native payment and Alipay personally pay products. It is clear that this experience will not be good, so ready to support micro-channel and Alipay the same time through a two-dimensional code.

Call micro-channel Native python sdk get paid url

wxpay = WXPay(app_id=WXAPPID, mch_id=WXMCHID, key=WXKEY, cert_pem_path=None, key_pem_path=None, timeout=6000, use_sandbox=False)
wxresp = wxpay.unifiedorder(dict(body='三盛国际广场-停车缴费-%s' % plateno,
                                    out_trade_no='%s' % (orderNo,),
                                    product_id=plateno,
                                    total_fee=payable,
                                    time_start=datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
                                    time_expire=(datetime.datetime.now() + datetime.timedelta(minutes=5)).strftime("%Y%m%d%H%M%S"),
                                    notify_url='https://apiserver/wxnotify',
                                    trade_type='NATIVE'))
if wxresp['return_code'].upper() == 'SUCCESS' and wxresp['result_code'].upper() == 'SUCCESS' and wxresp['appid'] == WXAPPID:
    wxurl = wxresp['code_url']

wxurl is such a format similar to the following:
weixin://wxpay/bizpayurl?sign=XX&appid=XX&mch_id=XX&product_id=XX&time_stamp=XX&nonce_str=XX

Call Alipay python sdk get personally pay url

alipay_client_config = AlipayClientConfig()
alipay_client_config.server_url = 'https://openapi.alipay.com/gateway.do'
alipay_client_config.app_id = ALI_APPID
alipay_client_config.app_private_key = ALI_PRI_KEY
alipay_client_config.alipay_public_key = ALI_PUB_KEY
aliclient = DefaultAlipayClient(alipay_client_config=alipay_client_config, logger=logger)
alimodel = AlipayTradePrecreateModel()
alimodel.out_trade_no = orderNo
alimodel.total_amount = payable / 100
alimodel.subject = "三盛国际广场-停车费-%s" % plateno
alimodel.qr_code_timeout_express = "5m"
alirequest = AlipayTradePrecreateRequest(biz_model=alimodel)
udf_params = dict()
udf_params[P_NOTIFY_URL] = "https://apiserver/alinotify"
alirequest.udf_params = udf_params

aliresponse = aliclient.execute(alirequest)
if aliresponse:
    response = AlipayTradePrecreateResponse()
    response.parse_response_content(aliresponse)
    if response.is_success():
        aliurl = response.qr_code

aliurl is such a format similar to the following:

https://qr.alipay.com/bavh4wjlxf12tper3a

In the first version, the two-dimensional code displayed payment machines are micro-channel and Alipay server returned to our encoding parameters become, since need a code to pay, obviously can not be directly used, after all, are not these two giants support its own APP sweep the other side of the two-dimensional code.

So we think that through a two-dimensional code of our own generation as a bridge, after obtaining the payment parameters micro letter and Alipay return, save temporary down and transfer production with arguments H5 page to a payment machines generate two-dimensional code scan code to the user when the app scan code parses the page address access, the server according to the app you can jump browser agent information corresponding pay url.
One yards payment timing diagram

if 'MicroMessenger' in agent:
#生成微信Native支付url
    return redirect(wxurl)
elif 'Alipay' in agent:
#生成支付宝当面付支付url
    return redirect(aliurl)
else:
    return '请打开微信或支付宝扫描付款二维码!'

This logic appears to be no problem, it is the perfect solution to the problem of the user experience. In fact there is also a pit, is Alipay personally pay this operation without any problems, while the micro-channel pay does not allow this operation, the micro-channel two-dimensional code will determine the payment is direct access through the camera scan or browser to jump over, when it is judged non scan code will direct your browser to refuse to pay, because micro-channel pay to do so may avoid security problems.

Alipay to pay in person

Since Native micro-channel can not pay directly, I can only Quxianjiuguo, because we already had a preliminary version of H5 pay parking fees, so this directly used reinvented a little, when it is determined when the micro-channel scan code, call micro-letter JSAPI payment, complete payment within the H5 page.

if 'MicroMessenger' in agent:
    #生成微信h5支付url
    return redirect(wxh5url)
elif 'Alipay' in agent:
    #生成支付宝当面付支付url
    return redirect(aliurl)
else:
    return '请打开微信或支付宝扫描付款二维码!'

Alipay pay than face to face, it needs to do a H5 payment page, to make the payment experience and native consistent, we refer to the official page of H5 payment style.

Micro-channel pay H5 page

Such a process ran down, the micro-channel and basic public Alipay pay a two-dimensional code to solve the problem, back pay if you plan to support QQ, Baidu wallet, paid Jingdong classes can also Yihuhuhuapiao.

Guess you like

Origin www.cnblogs.com/minibear2000/p/11645987.html