支付宝手机网站支付怎么把form返回到前端?response.getWriter().write

shaft_V 2019-06-12 02:41:10
理想型: 在支付宝容器里 自己的页面,->点击按钮->访问后端接口->生成支付宝form,直接用response打印出form->支付宝APP自动跳出支付界面,输入密码支付..

现在的问题是, response.getWriter().write(form) 完全没有反应...
原来用jsp页面,直接form方式提交,会自动唤醒支付界面, 但是VUE下, 没有任何反应...

请问大佬这个该怎么解决? 谢谢

try {
form = alipayClient.pageExecute(alipayRequest).getBody(); //调用SDK生成表单
} catch (AlipayApiException e) {
e.printStackTrace();
}
httpResponse.setContentType("text/html;charset=" + CHARSET);
httpResponse.getWriter().write(form);//直接将完整的表单html输出到页面
httpResponse.getWriter().flush();
httpResponse.getWriter().close();
}

...全文
2017 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43307990 2019-09-19
  • 打赏
  • 举报
回复
方便加一下qq吗?跟您交流一下 不知是否方便!
shaft_V 2019-09-18
  • 打赏
  • 举报
回复
引用 10 楼 weixin_43307990 的回复:
请问一下楼主,您这边后端的form表单 传给前端 前端的jsp页面您是怎么处理的呢?方便加下qq 请教一下您!谢谢!
JSP是之前人写的,用的是老版本, 是把支付宝所有参数生成一个url链接, 然后在jsp页面 直接response.sendRedirect(url); (JSP直接写Java代码) url开头是支付宝网关 后面带着签约所需要的参数
weixin_43307990 2019-09-18
  • 打赏
  • 举报
回复
请问一下楼主,您这边后端的form表单 传给前端 前端的jsp页面您是怎么处理的呢?方便加下qq 请教一下您!谢谢!
shaft_V 2019-08-05
  • 打赏
  • 举报
回复
忘了说结论.. 就是纯粹地把form里面除了最后一行的js:document.submit...... 什么的去掉 然后把 对应的from传给前端,前端放个按钮,点击提交. 另,可能会出现,解约后, 再申请签约,这种不行的情况. 这时需要联系支付宝的技术人员,(在支付宝对接群里, 不得不说,支付宝客服/技术人员的态度,比微信真的是好得太多了!)
shaft_V 2019-06-13
  • 打赏
  • 举报
回复
不行.. 方法 void() 方法内 response.getWrite(url) ; 方法String() 方法内 return url @ResponseBody 方法 String() return url
Dkodak 2019-06-13
  • 打赏
  • 举报
回复
@RequestMapping(value = "**", produces = "text/html; charset=UTF-8",method= RequestMethod.POST) 换成这个自动打开并跳转路径 String url = alipayClient.pageExecute(alipayRequest,"get").getBody();
shaft_V 2019-06-12
  • 打赏
  • 举报
回复
引用 5 楼 a_b_a_b_a_b_a_b 的回复:
不是Vue,也不是ajax,form表单提交到controller,controller直接这样写的。
谢谢. 对,是在controller里写. 原来是JSP页面, 在支付宝里 只需要请求后台生成订单的接口,然后再controller里直接
// 调用SDK生成表单
            form = client.pageExecute(alipay_request).getBody();
            response.setContentType("text/html;charset=" + AlipayConfig.input_charset);
            response.getWriter().write(form);//直接将完整的表单html输出到页面
            response.getWriter().flush();
            response.getWriter().close();
但是呢, 现在界面是VUE写的, 发现直接 response.getWriter().write(form); 没有反应.. (含有自动跳转js) 现在的解决方法是 把form截取<script>前内容,然后前端创建html 再次提交.. 没有response直接 write干脆. 那直接write html(包含form,自动提交,还有alipay的js)呢,,这边还是不行, 因为 html直接打印时,发现 和外层的html开头冲突了, 标签变成了内容(灰色字符).
a_b_a_b_a_b_a_b 2019-06-12
  • 打赏
  • 举报
回复
不是Vue,也不是ajax,form表单提交到controller,controller直接这样写的。
shaft_V 2019-06-12
  • 打赏
  • 举报
回复
引用 3 楼 a_b_a_b_a_b_a_b 的回复:
resp.setHeader("Content-Type", "text/html;charset=utf-8");
PrintWriter out = resp.getWriter();
System.out.println(client.buildPostForm(request));
out.write("<html>");
out.write("<head>");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
out.write("</head>");
out.write("<body>");
out.write(form);
out.write("</body>");
out.write("</html>");
以前这样写过,可以的。
前端是VUE框架的吗? 需要前端做处理吗(form提交 还是ajax 后台接口)? 我用上面那种,前端把<html>...~<form> 中间的那段吃掉了, 如果只传form的 body, 发现<script> 不能存在于中间. 我先试试你这种. 谢谢帮助!
a_b_a_b_a_b_a_b 2019-06-12
  • 打赏
  • 举报
回复
resp.setHeader("Content-Type", "text/html;charset=utf-8");
PrintWriter out = resp.getWriter();
System.out.println(client.buildPostForm(request));
out.write("<html>");
out.write("<head>");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
out.write("</head>");
out.write("<body>");
out.write(form);
out.write("</body>");
out.write("</html>");
以前这样写过,可以的。
shaft_V 2019-06-12
  • 打赏
  • 举报
回复
引用 1 楼 a_b_a_b_a_b_a_b 的回复:
生成的form内容是什么啊,有没有form自动提交代码啊,是不是需要自己拼接自动提交js代码啊。
谢谢! form的内容是提交到支付宝的<form name="punchout_form" method="post" action="https://openapi.alipay.com/gateway.do?charset=UTF-8&method=alipay.trade.wap.pay... 有form自动提交代码(body里自带的,支付宝返回的),<script>document.forms[0].submit();</script> 不需要自己拼接..
a_b_a_b_a_b_a_b 2019-06-12
  • 打赏
  • 举报
回复
生成的form内容是什么啊,有没有form自动提交代码啊,是不是需要自己拼接自动提交js代码啊。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧