手机网站接入支付宝在线支付的流程代码

首先给大家推荐一下我老师大神的人工智能教学网站。教学不仅零基础,通俗易懂,而且非常风趣幽默,还时不时有内涵黄段子!点这里可以跳转到网站

首先,创建一个支付宝手机网站支付的应用,里面会有

https://openhome.alipay.com/platform/isvAppPage.htm#/app/2019042264289117/package

但是,这个产品是需要签约

代码实现:

package application.service.facetoface; import com.alipay.api.AlipayApiException;import com.alipay.api.AlipayClient;import com.alipay.api.DefaultAlipayClient;import com.alipay.api.domain.AlipayTradeWapMergePayModel;import com.alipay.api.domain.AlipayTradeWapPayModel;import com.alipay.api.request.AlipayTradeWapPayRequest;import lombok.extern.slf4j.Slf4j;import org.springframework.context.annotation.Lazy;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; @Service@Lazy@Scope("singleton")@Slf4jpublic class AliPayService {     private final static String APP_ID = "2019042264282184";    private final static String APP_PRIVATE_KEY = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCqGrUGv0stPew24OGzM1XcqIogmvhB5k+RJOzCpgX382mlINiNvKYrSsKy2GHdNc+FKUHyvwlpu4gqx4r/I9SaCf8aQbo9cZj9aGfrxq+eHsQkRlS8h8pOQkCtbA/o3VsPVHLKHiQLyRqL9Y0FYigfmuBBzcmpaml6kzSfnskdbYe5uxpN4/OlzI6aHTdXlV42tpIysGX2O/udbLeVhfT5p8xOqlCkCAzlkvuBm4i9EuI61S0D3PS1ngGW1UZ5ciYJaORm/4LxX9h/lBg+ABeCcY7GqJ5D6y7RqyHHT5WKF9YbKUCm+IQBbAtQR1vY68kmgXLuEsul+pc/vLPcKa5tAgMBAAECggEBAJy3bE6iEQXGhgjtWKM7yYA4+sEdZVl5cZbceRC/2sHczVkoELtMsZ8zCnuxJUCjYeRh5XNak7aI4uPe4W08upOMYC31njsbnILjHNM5QvUfjT+KWGk1hapiGaps4597yHgwKm2SJU2CYuXNPbZW/3ZWvwOBL6jY9ALM+m+Q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Y = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhqsWfleEHenZkfnelFpi05xBNQoclvDbObHjt0VgQA5c8up24ijx0/IcV6Cl8nC3sc6MXuYT8ouAOSDrR/IDUmuS8UD/oxOlfwdvgIcnykeJditlPeWlAHfFw+T2papdNcWEHrOZFYNsLJ+AJylA8uCcY/uurxf6Ywuip//UTrN3xLnHBCs2uDSz2yDs/zF7YEK7A+hbnyzw/mGEHrGhR0wLqu1gnrcN5veDDXPb4dUNgLXl9REJS5FR4J6DEiHci2rjSqUGIrj0O5R2RW5edm1ZEY+QgizVpO4bUO6Yvf0QtHJRoZjgLhH6DEK76yt2XE5WzLTdlp84I+I2gyHGmwIDAQAB";    private final static String CHARSET ="UTF-8";     public void alipPay(HttpServletResponse httpServletResponse) throws Exception{        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2"); //获得初始化的AlipayClient        AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest();//创建API对应的request        AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();         model.setOutTradeNo(System.currentTimeMillis()+"");//设置支付宝支付的订单号        model.setSubject("商品名称");//商品名称        model.setTotalAmount("0.01");//支付金额        model.setBody("这个是一个商品支付");//商品描述        model.setTimeoutExpress("30m");//超时时间        model.setProductCode("000");//商品Code        //设置参数        alipayRequest.setBizModel(model);        alipayRequest.setNotifyUrl("https://www.baidu.com");        alipayRequest.setReturnUrl("https://www.baidu.com");        String form="";        try {            form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单        } catch (AlipayApiException e) {            e.printStackTrace();        }         System.out.println(form);        httpServletResponse.setContentType("text/html;charset="+CHARSET);        httpServletResponse.getWriter().write(form);//直接将完整的表单html输出到页面        httpServletResponse.getWriter().flush();        httpServletResponse.getWriter().close();    }}

点这里可以跳转到人工智能网站