支付宝支付-集成服务端和客户端

服务端 

在pom文件中添加.

        <dependency>
            <groupId>com.alipay.sdk</groupId>
            <artifactId>alipay-sdk-java</artifactId>
            <version>4.10.204.ALL</version>
        </dependency>

 讲一下

sdkExecute和pageExecute的区别.

sdkExecute是作为app的sdk拼接参数来使用.这个后面降到.

pageExecute是作为form表单放入html中.直接转就行

        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APPID, APP_PRIVATE, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2");
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
        AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setBody("商品");
        model.setSubject("商品名称");
        // 唯一订单号,保证唯一就行
        model.setOutTradeNo(System.currentTimeMillis() + "");
        model.setTimeoutExpress("30m");
        // 价格
        model.setTotalAmount("0.0.1");
        model.setProductCode("QUICK_MSECURITY_PAY");
        request.setBizModel(model);
        request.setNotifyUrl("唤醒地址");
        try {
            //这里和普通的接口调用不同,使用的是sdkExecute
            AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
            return response.getBody();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        return "";

客户端操作

   final String orderInfo = "将服务端返回的数据放到这里";
        final Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(PayDemoActivity.this);
                Map<String, String> result = alipay.payV2(orderInfo, true);
                Log.i("msp", result.toString());

                Message msg = new Message();
                msg.what = SDK_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        // 必须异步调用
        Thread payThread = new Thread(payRunnable);
        payThread.start();

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于动态创建UDP服务端客户端,你可以使用Spring Boot提供的spring-boot-starter-integration模块来实现。下面是一个简单的示例: 首先,确保在你的项目中引入了spring-boot-starter-integration依赖。在pom.xml文件中添加以下内容: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-integration</artifactId> </dependency> ``` 接下来,你可以创建一个Spring Boot应用程序,并使用集成组件来动态创建UDP服务端客户端。以下是示例代码: ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.IntegrationFlows; import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter; import org.springframework.integration.ip.udp.UnicastSendingMessageHandler; @SpringBootApplication public class UdpApplication { public static void main(String[] args) { SpringApplication.run(UdpApplication.class, args); } @Bean public IntegrationFlow udpInboundFlow() { return IntegrationFlows.from(udpInboundAdapter()) .handle("udpServer", "handleMessage") .get(); } @Bean public UnicastReceivingChannelAdapter udpInboundAdapter() { UnicastReceivingChannelAdapter adapter = new UnicastReceivingChannelAdapter(8888); adapter.setOutputChannelName("udpInboundChannel"); return adapter; } @Bean public IntegrationFlow udpOutboundFlow() { return IntegrationFlows.from("udpOutboundChannel") .handle(udpOutboundAdapter()) .get(); } @Bean public UnicastSendingMessageHandler udpOutboundAdapter() { return new UnicastSendingMessageHandler("localhost", 9999); } @Bean public UdpServer udpServer() { return new UdpServer(); } } import org.springframework.messaging.Message; import org.springframework.stereotype.Component; @Component public class UdpServer { public void handleMessage(Message<String> message) { // 处理UDP服务端接收到的消息 System.out.println("Received message: " + message.getPayload()); } } ``` 在上面的示例中,我们定义了一个UDP服务端和一个UDP客户端服务端使用UnicastReceivingChannelAdapter从8888端口接收消息,并通过UdpServer类的handleMessage方法进行处理。客户端通过UnicastSendingMessageHandler发送消息到localhost的9999端口。 注意:请根据你的实际需求修改端口号和处理逻辑。 这样,你就可以通过运行Spring Boot应用程序来创建动态的UDP服务端客户端了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值