/** 生成签名 */ private String genPackageSign(List<NameValuePair> params) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < params.size(); i++) { sb.append(params.get(i).getName()); sb.append('='); sb.append(params.get(i).getValue()); sb.append('&'); } sb.append("key="); sb.append(Constants.API_KEY); String packageSign = MD5.getMessageDigest(sb.toString().getBytes()).toUpperCase(); Log.e("orion", packageSign); return packageSign; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pay); show = (TextView) findViewById(R.id.editText_prepay_id); req = new PayReq(); sb = new StringBuffer(); msgApi.registerApp(Constants.APP_ID); // 生成prepay_id Button payBtn = (Button) findViewById(R.id.unifiedorder_btn); payBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { GetPrepayIdTask getPrepayId = new GetPrepayIdTask(); getPrepayId.execute(); } }); Button appayBtn = (Button) findViewById(R.id.appay_btn); appayBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { sendPayReq(); } }); // 生成签名参数 Button appay_pre_btn = (Button) findViewById(R.id.appay_pre_btn); appay_pre_btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { genPayReq(); } }); String packageSign = MD5.getMessageDigest(sb.toString().getBytes()).toUpperCase(); }
private String genNonceStr() { Random random = new Random(); return MD5.getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes()); }