JSP对接语音通知接口DEMO示例

点击下载

语音通知接口接入指南点击访问

String postUrl = "http://api.vm.ihuyi.com/webservice/voice.php?method=Submit";

//接口类型:互亿无线语音通知接口。
//账户注册:请通过该地址开通账户  http://user.ihuyi.com/?exClaO
//注意事项:
//(1)调试期间,请仔细阅读接口文档;
//(2)请使用APIID(查看APIID请登录用户中心->语音通知->帐户及签名设置->APIID)及 APIkey来调用接口;
//(3)该代码仅供接入互亿无线语音通知接口参考使用,客户可根据实际需要自行编写;

String account = "用户名";//用户名是登录用户中心->语音通知->帐户参数设置->APIID
String password = "密码";//查看密码请登录用户中心->语音通知->帐户参数设置->APIKEY
String mobile = "135xxxxxxxx";//手机号码
String content = "您的订单号是:0648。已由顺风快递发出,请注意查收。";


try {

	URL url = new URL(postUrl);
	HttpURLConnection connection = (HttpURLConnection) url.openConnection();
	connection.setDoOutput(true);//允许连接提交信息
	connection.setRequestMethod("POST");//网页提交方式“GET”、“POST”
	connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
	connection.setRequestProperty("Connection", "Keep-Alive");
	StringBuffer sb = new StringBuffer();
	sb.append("account="+account);
	sb.append("&password="+password);
	sb.append("&mobile="+mobile);
	sb.append("&content="+content);
	OutputStream os = connection.getOutputStream();
	os.write(sb.toString().getBytes());
	os.close();

	String line, result = "";
	BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
	while ((line = in.readLine()) != null) {
		result += line + "\n";
	}
	in.close();
	out.println(result);

} catch (IOException e) {
	e.printStackTrace(System.out);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用JSP、Servlet和JDBC对接支付宝接口,您需要进行以下步骤: 1. 注册支付宝开发者账号并创建应用。 2. 下载支付宝SDK,并将其添加到您的项目中。 3. 在JSP页面中添加一个表单,该表单包含用户要支付的详细信息,例如订单号、商品描述和价格。 4. 创建一个Servlet,该Servlet将获取表单数据并将其发送到支付宝接口。 5. 在Servlet中使用JDBC连接到您的数据库,并将支付信息保存在数据库中。 6. 从支付宝服务器接收响应,并在JSP页面上显示支付结果。 7. 在Servlet中更新数据库中的订单状态,以便您可以跟踪订单状态。 以下是一个简单的示例: ``` <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.*" %> <%@ page import="com.alipay.api.AlipayApiException"%> <%@ page import="com.alipay.api.AlipayClient"%> <%@ page import="com.alipay.api.DefaultAlipayClient"%> <%@ page import="com.alipay.api.request.AlipayTradePagePayRequest"%> <%@ page import="java.sql.*" %> <% // 获取表单数据 String orderNo = request.getParameter("orderNo"); String subject = request.getParameter("subject"); String totalAmount = request.getParameter("totalAmount"); // 连接到数据库 Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "password"); String sql = "INSERT INTO orders (orderNo, subject, totalAmount) VALUES (?, ?, ?)"; pstmt = conn.prepareStatement(sql); pstmt.setString(1, orderNo); pstmt.setString(2, subject); pstmt.setString(3, totalAmount); pstmt.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } // 构造支付宝请求 String app_id = "your_app_id"; String merchant_private_key = "your_merchant_private_key"; String alipay_public_key = "your_alipay_public_key"; String notify_url = "http://www.yourdomain.com/notify_url.jsp"; String return_url = "http://www.yourdomain.com/return_url.jsp"; AlipayClient client = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", app_id, merchant_private_key, "json", "UTF-8", alipay_public_key, "RSA2"); AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest(); alipayRequest.setReturnUrl(return_url); alipayRequest.setNotifyUrl(notify_url); alipayRequest.setBizContent("{\"out_trade_no\":\"" + orderNo + "\"," + "\"total_amount\":\"" + totalAmount + "\"," + "\"subject\":\"" + subject + "\"," + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}"); String form = ""; try { form = client.pageExecute(alipayRequest).getBody(); } catch (AlipayApiException e) { e.printStackTrace(); } // 显示支付宝支付页面 out.print(form); %> ``` 请注意,以上仅为示例代码,您需要根据自己的实际情况进行修改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值