In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use python code to achieve payment jump page, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Public class AlipayUtil {
Private Activity activity
The interface to jump after successful payment by private Class clz;//
Private String orderid
Private String id
Public AlipayUtil (Activity activity,Class clz,int alipayType, String orderid,String id) {
This.activity=activity
This.clz = clz
This.alipayType=alipayType
This.orderid = orderid
This.id = id
}
/ / merchant PID
Public static final String PARTNER = (String) PropertiesParser.get ("PARTNER")
/ / merchant collection account
Public static final String SELLER = (String) PropertiesParser.get ("SELLER")
/ / Merchant private key in pkcs8 format
Public static final String RSA_PRIVATE = (String) PropertiesParser.get ("RSA_PRIVATE")
/ / Alipay public key
Public static final String RSA_PUBLIC = (String) PropertiesParser.get ("RSA_PUBLIC")
/ / Server Asynchronous Notification Page path URL
/ / public static final String NOTIFY_URL=ConstUtil.BASE_URL+ "alipay/index/"
Public static final String NOTIFY_URL=ConstUtil.BASE_URL+ "alipay"
/ / timeout for unpaid transactions
Public static final String IT_B_PAY= (String) PropertiesParser.get ("IT_B_PAY")
Private static final int SDK_PAY_FLAG = 1
Private static final int SDK_CHECK_FLAG = 2
Private int resultType; / / result type 1 success 0 failure caused by user cancellation 3 is not the failure of user cancellation
Private int alipayType; / / Operation Type 1 pay 2 recharge
The display title of the private String title; / / execute interface dialog box
Private String content;// content
Private String money; / / payment, top-up fee
Private void setTitleAndContent () {
If (alipayType==2) {
If (resultType==1) {
Title= "recharge successfully"
Content= "using Alipay to recharge successfully"
} else if (resultType==0) {
Title= "recharge failure"
Content= "recharge failed, user canceled"
} else {
Title= "recharge failure"
Content= "recharge result is being confirmed. The transaction will be closed automatically for more than 15 minutes and the transaction amount will be refunded automatically."
}
} else if (alipayType==1) {
If (resultType==1) {
Title= "payment success"
Content= "pay successfully with Alipay"
} else if (resultType==0) {
Title= "payment failed"
Content= "payment failed, user canceled"
} else {
Title= "payment failed"
Content= "payment result is being confirmed. The transaction will be closed automatically after 15 minutes and the transaction amount will be refunded automatically."
}
}
}
Private Handler mHandler = new Handler () {
Public void handleMessage (Message msg) {
Switch (msg.what) {
Case SDK_PAY_FLAG: {
PayResult payResult = new PayResult ((String) msg.obj)
/ / Alipay returns the payment result and endorsement. It is recommended to verify the signature information of Alipay with the public key provided by Alipay at the time of signing the contract.
String resultInfo = payResult.getResult ()
String resultStatus = payResult.getResultStatus ()
/ / if the resultStatus is "9000", the payment is successful. For more information on the meaning of the status code, please see the API documentation.
If (TextUtils.equals (resultStatus, "9000")) {
/ / payment is successful
ResultType=1
} else {
/ / if the resultStatus is not "9000", the payment may fail.
/ / "8000" means that the payment result is still waiting for payment result confirmation due to payment channel or system reasons. Whether the final transaction is successful is subject to the server asynchronous notification (low probability status).
If (TextUtils.equals (resultStatus, "8000")) {
/ / confirmation of payment result
ResultType=3
} else {
ResultType=0
/ / other values can be judged as payment failure, including the user canceling the payment voluntarily, or the error returned by the system
}
}
SetTitleAndContent ()
/ / use the dialog box to prompt the user to execute the result of the payment
DialogUtil.moneyPayResultDialog (activity, clz, title, content, new OnClickListener () {
@ Override
Public void onClick (View v) {
DialogUtil.cancleMoneyPayResultDialog ()
If (resultType==1) {
If (alipayType==1) {/ / payment successfully redirects the main interface
If (orderid.substring (0,1) .equals ("o")) {
Intent intent = new Intent (activity, clz)
Intent.putExtra ("orderid", orderid.substring (1))
Activity.startActivity (intent)
Activity.finish ()
Activity.overridePendingTransition (R.anim.finish_enter, R.anim.finish_exit)
} else {
Intent intent = new Intent (activity, clz)
Orderid = id
Intent.putExtra ("orderid", orderid)
Activity.startActivity (intent)
Activity.finish ()
Activity.overridePendingTransition (R.anim.finish_enter, R.anim.finish_exit)
}
} else if (alipayType==2) {/ / recharge successfully finish the current interface returns to the balance interface to transfer the recharge amount
Activity.setResult (Activity.RESULT_OK,new Intent () .putExtra ("money", money)
Activity.finish ()
Activity.overridePendingTransition (R.anim.finish_enter, R.anim.finish_exit)
}
} else if (resultType==0) {/ / payment failure stays on the current interface
}
}
});
Break
}
Case SDK_CHECK_FLAG:
PrintUtil.toastLong (activity,msg.obj.toString ())
If (! (Boolean) msg.obj) {
PrintUtil.toastLong (activity, "you do not have Alipay installed or do not have a valid Alipay account!")
}
Break
Default:
Break
}
}
}
/ * *
* pay for Alipay
* @ name of the param subject product
* @ param body description of the product
Price of * @ param price goods
* @ param order_id order number
, /
Public void pay (String subject,String body,String order_id,String price,String id) {
Money=price
If (TextUtils.isEmpty (PARTNER) | | TextUtils.isEmpty (RSA_PRIVATE) | | TextUtils.isEmpty (SELLER)) {
PrintUtil.toastLong (activity, "merchant information is incomplete and payment cannot be made")
Return
}
/ / order
String orderInfo = getOrderInfo (subject, body, order_id,price)
/ / A pair of orders are signed by RSA
String sign = sign (orderInfo)
Try {
/ / only need to encode sign with URL
Sign = URLEncoder.encode (sign, "UTF-8")
} catch (UnsupportedEncodingException e) {
E.printStackTrace ()
}
/ / complete order information that conforms to Alipay parameter specifications
Final String payInfo = orderInfo + "& sign=\" + sign + "\" & "
+ getSignType ()
Runnable payRunnable = new Runnable () {
@ Override
Public void run () {
/ / construct PayTask object
PayTask alipay = new PayTask (activity)
/ / call the payment API to get the payment result
String result = alipay.pay (payInfo)
Message msg = new Message ()
Msg.what = SDK_PAY_FLAG
Msg.obj = result
MHandler.sendMessage (msg)
}
}
/ / must be called asynchronously
Thread payThread = new Thread (payRunnable)
PayThread.start ()
}
/ * *
* check whether the device has authentication alipay account.
* query whether Alipay authentication account exists in terminal equipment.
*
, /
/ / public void check () {
/ / Runnable checkRunnable = new Runnable () {
/ / @ Override
/ / public void run () {
/ construct PayTask object
/ / PayTask payTask = new PayTask (activity)
/ / call the query API to get the query result
/ / boolean isExist = payTask.checkAccountIfExist ()
/ /
/ / Message msg = new Message ()
/ / msg.what = SDK_CHECK_FLAG
/ / msg.obj = isExist
/ / mHandler.sendMessage (msg)
/ /}
/ /}
/ /
/ / Thread checkThread = new Thread (checkRunnable)
/ / checkThread.start ()
/ /
/ /}
/ * *
* get the sdk version. Get the SDK version number
*
, /
Public void getSDKVersion () {
PayTask payTask = new PayTask (activity)
String version = payTask.getVersion ()
PrintUtil.toast (activity, version)
}
/ * *
* create the order info. Create order information
* @ return
, /
Public String getOrderInfo (String subject, String body, String order_id,String price) {
/ / ID as the signing partner
String orderInfo = "partner=" + "\"+ PARTNER +"\ ""
/ / sign the seller's Alipay account
OrderInfo + = "& seller_id=" + "\"+ SELLER +"\ ""
/ / the unique order number of the merchant website
OrderInfo + = "& out_trade_no=" + "\"+ order_id +"\ ""
/ / Product name
OrderInfo + = "& subject=" + "\"+ subject +"\ ""
/ / Product details
OrderInfo + = "& body=" + "\"+ body +"\ ""
/ / the amount of goods
OrderInfo + = "& total_fee=" + "\"+ price +"\ ""
/ / Server async notification page path
OrderInfo + = "& notify_url=" + "\" + NOTIFY_URL
+ "\"
/ / Service API name, fixed value
OrderInfo + = "& service=\" mobile.securitypay.pay\ ""
/ / payment type, fixed value
OrderInfo + = "& payment_type=\" 1\ ""
/ / Parameter coding, fixed value
OrderInfo + = "& _ input_charset=\" utf-8\ ""
/ / set the timeout for unpaid transactions
/ / the default is 30 minutes. If the transaction times out, the transaction will be closed automatically.
/ / value range: 1m~15d.
/ / m-minute, h-hour, d-day, 1c-day (no matter when the transaction is created, it closes at 0: 00).
/ / the value of this parameter does not accept decimal point. For example, 1.5h can be converted to 90m.
OrderInfo + = "& it_b_pay=\" + IT_B_PAY+ "\"
/ / extern_token is the alipay_open_id obtained through fast login authorization. With this parameter, the user will use the authorized account to make payment.
/ / orderInfo + = "& extern_token=" + "\"+ extern_token +"\ ""
/ / after Alipay processes the request, the current page jumps to the path of the merchant's specified page, which can be left empty.
OrderInfo + = "& return_url=\" m.alipay.com\ ""
/ / to call bank card payment, you need to configure this parameter, participate in the signature, and fix the value (you need to sign "Wireless Bank Card Express payment" to use it)
/ / orderInfo + = "& paymethod=\" expressGateway\ ""
Return orderInfo
}
/ * *
* sign the order info. Sign the order information
*
* @ param content
* order information to be signed
, /
Public String sign (String content) {
Return SignUtils.sign (content, RSA_PRIVATE)
}
/ * *
* get the sign type we use. Get signature method
*
, /
Public String getSignType () {
Return "sign_type=\" RSA\ ""
}
}
After reading the above, have you mastered how to use python code to implement the payment jump page? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.