Android UnionPay pay Access Report Nullexception exception

Source: Internet
Author: User

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.unionpay.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:  "XX"  -  start UnionPay formal environment   "" " -  Connect UnionPay test environment   Test   card number: 6226440123456785 *  Password: 111101 *****************************************************************/private final  static String mMode =  "Rivate static final string tn_url_01";p  =  "HTTP://202.101.25.178:8080/SIM/GETTN";p rivate static progressdialog  mloadingdialog = null;private static activity activity;private static  Unionpay unionpay = new unionpay ();p Ublic static void unionpay (Activity  activity)  {unionpay.activity = activity;mloadingdialog = progressdialog.show ( Activity, // context "",  // title "is trying to get TN, please wait ...",  // messagetrue);  //   Whether the progress is indeterminate, this is only related to creating a progress bar/************************************************* *  Step 1: Start from the network, get the transaction serial number is TN  ************************************************/new thread (UnionPay). Start ();// //Payment amount   Order Amount// string orderamount =  "1533";// //// string merchantno =  "805920100000069";// //merchant Order number//  String orderNO =  "467934311";// //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://mpay.sinoqy.com : 6283/qyapi/trans/gettn "// + "? orderamount= "+orderamount// + " &merchantNO= "+merchantNO  +  "&orderno=" + orderno// +  "&backurl=" +backurl// +  "&Sign=" +  SIGN;//// LOG.E ("",  "" +url);//// //get 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 (", " onresponse=  "+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 try again!"); Builder.setnegativebutton ("OK", New dialoginterface.onclickListener ()  {@Overridepublic  void onclick (Dialoginterface dialog,int which)  { Dialog.dismiss ();}}); Builder.create (). Show ();  else {tn =  (String)  msg.obj;/*************************************************  *  Step 2: Start the payment plugin via the UnionPay tool class  ************************************************/dostartunionpayplugin (activity,  tn, mmode);}}};/ /  UnionPay public static void dostartunionpayplugin (Activity activity, string tn,  string mode)  {log.e (", " Handlemessage "),// todo// orderinfo --order information is the transaction serial number, That is TN.  mode --  UnionPay Background Environmental identification, "00" will be launched in the formal environment of UnionPay,  "01" will be in the//  UnionPay test environment to initiate transactions Uppayassistex.startpaybyjar ( Activity, payactivity.class, null, null,tn, mode);} @Overridepublic  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;           bytearrayoutputstream baos = new bytearrayoutputstream ();           while  ((I = is.read ())  != -1)  {               baos.write (i);        &nbsP;  }          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 own integrated UnionPay payment, in

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 sav        Edinstancestate) {super.oncreate (savedinstancestate);           Setcontentview (R.layout.activity_main);   public void Click (View v) {//Call Unionpay.unionpay (this); }}


The following exception occurred:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/DC/wKiom1XusbCC0x3wAAFE_xFaWVI935.jpg "title=" QQ picture 20150908175923.png "alt=" Wkiom1xusbcc0x3waafe_xfawvi935.jpg "/>


Search for n long to find the problem: (Damn this file did not test)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/D9/wKioL1XutCjh3l6SAABGICEMCc4957.jpg "title=" Qq20150908180111.png "alt=" Wkiol1xutcjh3l6saabgicemcc4957.jpg "/>


I hope you will pay attention.

Android UnionPay pay Access Report Nullexception exception

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.