android studio扫条码功能,在Android studio开发集成支付宝的当面付功能(条码支付,扫码支付)时,均会出现Hostname找不到,头痛几天了...

private static final String APP_ID = "App_id";

private AlipayClient alipayClient;

private static final String APP_PRIVATE_KEY = "密钥";

private static final String APP_PUBLIC_KEY = "支付宝公钥";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", "GBK", APP_PUBLIC_KEY);

//条码支付

final AlipayTradePayRequest request = new AlipayTradePayRequest();

request.setBizContent("{" +

"    \"out_trade_no\":\"20150320010101001\"," +

"    \"scene\":\"bar_code,wave_code\"," +

"    \"auth_code\":\"28763443825664394\"," +

"    \"subject\":\"Iphone6 16G\"," +

"    \"seller_id\":\"2088102146225135\"," +

"    \"total_amount\":88.88," +

"    \"discountable_amount\":8.88," +

"    \"undiscountable_amount\":80.00," +

"    \"body\":\"Iphone6 16G\"," +

"      \"goods_detail\":[{" +

"                \"goods_id\":\"apple-01\"," +

"        \"alipay_goods_id\":\"20010001\"," +

"        \"goods_name\":\"ipad\"," +

"        \"quantity\":1," +

"        \"price\":2000," +

"        \"goods_category\":\"34543238\"," +

"        \"body\":\"特价手机\"," +

"        \"show_url\":\"http://www.alipay.com/xxx.jpg\"" +

"        }]," +

"    \"operator_id\":\"yx_001\"," +

"    \"store_id\":\"NJ_001\"," +

"    \"terminal_id\":\"NJ_T_001\"," +

"    \"alipay_store_id\":\"2016041400077000000003314986\"," +

"    \"extend_params\":{" +

"      \"sys_service_provider_id\":\"2088511833207846\"," +

"      \"hb_fq_num\":\"3\"," +

"      \"hb_fq_seller_percent\":\"100\"" +

"    }," +

"    \"timeout_express\":\"90m\"," +

"    \"royalty_info\":{" +

"      \"royalty_type\":\"ROYALTY\"," +

"        \"royalty_detail_infos\":[{" +

"                    \"serial_no\":1," +

"          \"trans_in_type\":\"userId\"," +

"          \"batch_no\":\"123\"," +

"          \"out_relation_id\":\"20131124001\"," +

"          \"trans_out_type\":\"userId\"," +

"          \"trans_out\":\"2088101126765726\"," +

"          \"trans_in\":\"2088101126708402\"," +

"          \"amount\":0.1," +

"          \"desc\":\"分账测试1\"," +

"          \"amount_percentage\":\"100\"" +

"          }]" +

"    }," +

"    \"sub_merchant\":{" +

"      \"merchant_id\":\"19023454\"" +

"    }" +

"  }");

new Thread(new Runnable() {

@Override

public void run() {

try {

AlipayTradePayResponse response = alipayClient.execute(request);

System.out.println("响应结果" + response.getBuyerPayAmount());

} catch (AlipayApiException e) {

e.printStackTrace();

}

}

}).start();

//扫码支付

findViewById(R.id.bt_sm).setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

final AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();//创建API对应的request类

request.setBizContent("{" +

"    \"out_trade_no\":\"20150320010101002\"," +

"    \"total_amount\":88.88," +

"    \"subject\":\"Iphone6 16G\"," +

"    \"store_id\":\"NJ_001\"," +

"    \"timeout_express\":\"90m\"," +

"  }");//设置业务参数

new Thread(new Runnable() {

@Override

public void run() {

try {

AlipayTradePrecreateResponse response = alipayClient.execute(request);

System.out.println("结果="+response.getQrCode());

} catch (AlipayApiException e) {

System.out.println("进入异常");

Log.e("1", "Exception: "+Log.getStackTraceString(e));

e.printStackTrace();

}

}

}).start();

}

});

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值