Android UnionPay payment access reports nullexception exception

Source: Internet
Author: User

Android UnionPay payment access reports nullexception exception

Package com. example. ex_example; import java. io. byteArrayOutputStream; import java. io. inputStream; import java.net. URL; import java.net. URLConnection; import android. app. activity; import android. app. alertDialog; import android. app. progressDialog; import android. content. dialogInterface; import android. OS. handler; import android. OS. message; import android. util. log; import com. unionpay. UPPayAssistEx; import com. uni Onpay. uppay. payActivity; public class UnionPay implements Runnable {// public static final int PLUGIN_VALID = 0; // public static final int PLUGIN_NOT_INSTALLED =-1; // public static final int PLUGIN_NEED_UPGRADE = 2; /*************************************** * ************************** mMode parameter explanation: "00"-start UnionPay official environment "01"-connect to UnionPay testing environment test card No.: 6226440123456785 * password: 111101 ********************************** * *****************************/Private final static String mMode = "01 "; private static final String TN_URL_01 = "http: // 202.101.25.178: 8080/sim/gettn"; private static ProgressDialog mLoadingDialog = null; private static Activity; private static UnionPay unionPay = new UnionPay (); public static void unionpay (Activity activity) {UnionPay. activity = activity; mLoadingDialog = ProgressDia Log. show (activity, // context "", // title "is trying to obtain tn. Please wait... ", // message true); // whether the progress is uncertain, this is only related to the creation of progress bars /********************************* * Step 1: starting from the network, obtain the transaction serial number, that is, TN *********************************** * ************/new Thread (unionPay ). start (); // payment order amount // String orderAmount = "1533"; // qianniu merchant ID // String merchantNO = "805920100000069 "; /// Merchant Order No. // String orderNO = "46793431 1 "; // notification Url // String backUrl =" http://www.baidu.com "; // signature key // String key =" 86Aab696Fed90bc691a7AfE0b6a269Ac "; /// signature field // String signcont = // merchantNO + "&" + orderNO + "&" + orderAmount + "&" + backUrl + "&" + key; //// Log. e ("", "" + signcont); // String sign = MD5.digest (signcont); // String sign = MD5Utils. generate (signcont); // Log. e ("", "sign =" + sign. length (); // String url = "http: // m Pay.sinoqy.com: 6283/qyapi/trans/getTn "// + "? OrderAmount = "+ orderAmount // +" & merchantNO = "+ merchantNO // +" & orderNO = "+ orderNO // +" & backUrl = "+ backUrl // + "& sign = "+ sign; //// Log. e ("", "" + url); // obtain TN // HTTPUtils. get (this, url, new VolleyListener () {// @ Override // public void onErrorResponse (VolleyError arg0) {// Log. e ("", "VolleyError =" + arg0); //} // @ Override // public void onResponse (String arg0) {// Log. e ("", "onR Esponse = "+ arg0); //} // UnionPay private static Handler mHandler = new Handler () {public void handleMessage (android. OS. message msg) {if (mLoadingDialog. isShowing () {mLoadingDialog. dismiss ();} String tn = ""; if (msg. obj = null | (String) msg. obj ). length () = 0) {AlertDialog. builder builder = new AlertDialog. builder (activity); builder. setTitle ("error prompt"); builder. setMessage ("network connection failed, please repeat Try! "); Builder. setNegativeButton ("OK", new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {dialog. dismiss () ;}}); builder. create (). show ();} else {tn = (String) msg. obj; /*************************************** * Step 2: use the UnionPay tool to start the payment plug-in ********************************** * ************/doStartUnionPayPlugin (activity, tn, mMode) ;}}; // UnionPay Public static void doStartUnionPayPlugin (Activity activity, String tn, String mode) {Log. e ("", "handleMessage"); // TODO // orderInfo -- the order information is the transaction serial number, that is, TN. // Mode -- UnionPay Background Environment identifier. "00" will initiate a transaction in the official UnionPay environment, and "01" will initiate a transaction in the // UnionPay testing environment. UPPayAssistEx. startPayByJAR (activity, PayActivity. class, null, null, tn, mode) ;}@ Override public void run () {Log. e ("", "run"); String tn = null; InputStream is; try {String url = TN_URL_01; URL myURL = new URL (url); URLConnection ucon = myURL. openConnection (); ucon. setConnectTimeout (120000); is = ucon. getInputStream (); int I =-1; Byte ArrayOutputStream baos = new ByteArrayOutputStream (); while (I = is. read ())! =-1) {baos. write (I);} tn = baos. toString (); is. close (); baos. close ();} catch (Exception e) {e. printStackTrace ();} Message msg = mHandler. obtainMessage (); msg. obj = tn; mHandler. sendMessage (msg );}}

This is my integrated UnionPay payment.
Package com. example. ex_example; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);} public void click (View v) {// call UnionPay. unionpay (this );}}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.