有什么书是java来java如何实现微信支付付的

&>&第三方APP微信支付Java服务端构建完整步骤
第三方APP微信支付Java服务端构建完整步骤
上传大小:173KB
第三方APP微信支付Java服务端构建完整步骤
综合评分:2(7位用户评分)
下载个数:
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var parentWrap = $(this).parents(".respond_box"),
q = parentWrap.find(".form1").serializeArray(),
resStr = $.trim(parentWrap.find(".res_area_r").val());
console.log(q);
//var res_area_r = $.trim($(".res_area_r").val());
if (resStr == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $target,
evt = e || window.
$target = $(evt.target || evt.srcElement);
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
//var mess = $(".res_area_r").val();
var mess = resS
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, data.com_username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
/*删除回复*/
$(".rightLi").on("click", '.del_comment_r', function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
//填充回复
function KeyP(v) {
var parentWrap = $(v).parents(".respond_box");
parentWrap.find(".res_area_r").val($.trim(parentWrap.find(".res_area").val()));
评论共有6条
谢谢你的分享,帮助了我的开发学习。
不用下了,就是复制其他地方的过来而已,还很不全
为何都是乱码
综合评分:
积分/C币:5
赤砂之蝎我爱罗
综合评分:
积分/C币:5
VIP会员动态
CSDN下载频道资源及相关规则调整公告V11.10
下载频道用户反馈专区
下载频道积分规则调整V1710.18
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
资源所需积分/C币
当前拥有积分
当前拥有C币
输入下载码
为了良好体验,不建议使用迅雷下载
第三方APP微信支付Java服务端构建完整步骤
会员到期时间:
剩余下载个数:
剩余积分:0
为了良好体验,不建议使用迅雷下载
积分不足!
资源所需积分/C币
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分/C币
当前拥有积分
当前拥有C币
(仅够下载10个资源)
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
为了良好体验,不建议使用迅雷下载
资源所需积分/C币
当前拥有积分
当前拥有C币
您的积分不足,将扣除 10 C币
为了良好体验,不建议使用迅雷下载
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可返还被扣除的积分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:
第三方APP微信支付Java服务端构建完整步骤&&文章详情
微信APP支付-Java后台实现
1 注册微信开放者平台
开发者平台地址:https://open.weixin.qq.com/
2 成为开发者
4 开通微信支付功能
5 设置商户号信息
APP 支付能力开通后,微信会给你一个商户号,用户和密码等信息。需要验证商户信息,还需要设置一个加密的密钥字段,这里就不一一细说了。
6 开发接口
微信APP支付接口,是很好调试的,(不像微信公众平台,需要80端口),可以直接在本地就可以进行调试。 具体业务就不细说,直接看代码就懂了。
1 基础信息配置
package com.qx.client.common.pay.weichart.
import java.util.P
import com.tom.util.properties.PropertiesU
import com.tom.util.system.RSystemC
public class WeiChartConfig {
* 预支付请求地址
public static final String
PrepayUrl = &https://api.mch.weixin.qq.com/pay/unifiedorder&;
* 查询订单地址
public static final String
OrderUrl = &https://api.mch.weixin.qq.com/pay/orderquery&;
* 关闭订单地址
public static final String
CloseOrderUrl = &https://api.mch.weixin.qq.com/pay/closeorder&;
* 申请退款地址
public static final String
RefundUrl = &https://api.mch.weixin.qq.com/secapi/pay/refund&;
* 查询退款地址
public static final String
RefundQueryUrl = &https://api.mch.weixin.qq.com/pay/refundquery&;
* 下载账单地址
public static final String
DownloadBillUrl = &https://api.mch.weixin.qq.com/pay/downloadbill&;
* 商户APPID
public static final String
AppId = &wxabcdefghjjsdfsd&;
* 商户账户 获取支付能力后,从邮件中得到
public static final String
MchId = &01&;
* 商户秘钥
32位,在微信商户平台中设置
public static final String
AppSercret = &qx79789&;
* 服务器异步通知页面路径
public static String notify_url = getProperties().getProperty(&notify_url&);
* 页面跳转同步通知页面路径
public static String return_url = getProperties().getProperty(&return_url&);
* 退款通知地址
public static String refund_notify_url = getProperties().getProperty(&refund_notify_url&);
* 退款需要证书文件,证书文件的地址
public static String refund_file_path = getProperties().getProperty(&refund_file_path&);
* 商品名称
public static String subject =
getProperties().getProperty(&subject&);
* 商品描述
public static String body = getProperties().getProperty(&body&);
private static
public static synchronized Properties getProperties(){
if(properties == null){
String path = System.getenv(RSystemConfig.KEY_WEB_HOME_CONF) + &/weichart.properties&;
properties = PropertiesUtil.getInstance().getProperties(path);
2 http /https请求的工具类
其中有需要证书的,也有不需要证书的。
证书是在需要退款接口的时候需要使用,直接把证书放在服务器上,然后传路径
package com.qx.client.common.pay.weichart.util.httpC
import java.io.BufferedR
import java.io.F
import java.io.FileInputS
import java.io.IOE
import java.io.InputStreamR
import java.io.OutputStreamW
import java.net.MalformedURLE
import java.net.URL;
import java.net.URLC
import java.security.KeyS
import java.util.M
import javax.net.ssl.SSLC
import org.apache.commons.httpclient.HttpC
import org.apache.commons.httpclient.methods.PostM
import org.apache.commons.httpclient.methods.StringRequestE
import org.apache.commons.httpclient.params.HttpMethodP
import org.apache.http.HttpE
import org.apache.http.client.methods.CloseableHttpR
import org.apache.http.client.methods.HttpP
import org.apache.http.conn.ssl.SSLConnectionSocketF
import org.apache.http.conn.ssl.SSLC
import org.apache.http.entity.StringE
import org.apache.http.impl.client.CloseableHttpC
import org.apache.http.impl.client.HttpC
import org.apache.http.util.EntityU
public class HttpClientUtil{
public static String post(String url,
Map&String, String& headMap,
Map&String, String& params){
HttpClient httpclient = new HttpClient();
httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, &UTF-8&);
PostMethod httpPost = new PostMethod(url);
if(null != headMap){
for(String key : headMap.keySet()){
httpPost.setRequestHeader(key, headMap.get(key));
if(null != params){
for(String pkey : params.keySet()){
httpPost.addParameter(pkey, params.get(pkey));
httpclient.executeMethod(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(httpPost.getResponseBodyAsStream()));
StringBuffer stringBuffer = new StringBuffer();
String str = &&;
while((str = reader.readLine()) != null){
stringBuffer.append(str);
reader.close();
return stringBuffer.toString();
}catch(Exception e){
e.printStackTrace();
public static String postHttplient(String url,
String xmlInfo){
HttpClient httpclient = new HttpClient();
httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, &UTF-8&);
PostMethod httpPost = new PostMethod(url);
httpPost.setRequestEntity(new StringRequestEntity(xmlInfo));
httpclient.executeMethod(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(httpPost.getResponseBodyAsStream()));
StringBuffer stringBuffer = new StringBuffer();
String str = &&;
while((str = reader.readLine()) != null){
stringBuffer.append(str);
reader.close();
return stringBuffer.toString();
}catch(Exception e){
e.printStackTrace();
* 需要加密执行的
* @param url
* @param xmlInfo
* @throws Exception
public static String postHttplientNeedSSL(String url,
String xmlInfo,
String cretPath,
String mrchId)
throws Exception{
//选择初始化密钥文件格式
KeyStore keyStore = KeyStore.getInstance(&PKCS12&);
//得到密钥文件流
FileInputStream instream = new FileInputStream(new File(cretPath));
//用商户的ID 来解读文件
keyStore.load(instream, mrchId.toCharArray());
instream.close();
//用商户的ID 来加载
SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, mrchId.toCharArray()).build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { &TLSv1& }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
//用最新的httpclient 加载密钥
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
StringBuffer ret = new StringBuffer();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(xmlInfo));
CloseableHttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
if(entity != null){
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent()));
while((text = bufferedReader.readLine()) != null){
ret.append(text);
EntityUtils.consume(entity);
response.close();
httpclient.close();
return ret.toString();
public static String postHtpps(String urlStr,
String xmlInfo){
URL url = new URL(urlStr);
URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setRequestProperty(&Pragma:&, &no-cache&);
con.setRequestProperty(&Cache-Control&, &no-cache&);
con.setRequestProperty(&Content-Type&, &text/charset=utf-8&);
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(), &utf-8&);
out.write(xmlInfo);
out.flush();
out.close();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuffer lines = new StringBuffer();
String line = &&;
for(line = br.readLine(); line != line = br.readLine()){
lines.append(line);
return lines.toString();
}catch(MalformedURLException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
4 调用API接口
其中包含 XML生成,和解析XML,请求参数字典排序,拼接密钥,MD5加密
package com.qx.client.common.pay.weichart.
import java.net.InetA
import java.net.UnknownHostE
import java.util.A
import java.util.D
import java.util.HashM
import java.util.M
import java.util.R
import java.util.S
import org.mobj.com.encoding.RMd5;
import org.mobj.com.xml.FXmlD
import org.mobj.com.xml.FXmlN
import org.mobj.com.xml.FXmlN
import com.qx.client.common.pay.weichart.config.WeiChartC
import com.qx.client.common.pay.weichart.util.httpClient.HttpClientU
public class WeiChartUtil{
* 返回状态码
public static final String ReturnCode = &return_code&;
* 返回信息
public static final String ReturnMsg = &return_msg&;
* 业务结果
public static final String ResultCode = &result_code&;
* 预支付交易会话标识
public static final String PrepayId = &prepay_id&;
* 得到微信预付单的返回ID
* @param orderId
商户自己的订单号
* @param totalFee
public static Map&String, String& getPreyId(String orderId,
String totalFee){
Map&String, String& reqMap = new HashMap&String, String&();
reqMap.put(&appid&, WeiChartConfig.AppId);
reqMap.put(&mch_id&, WeiChartConfig.MchId);
reqMap.put(&nonce_str&, getRandomString());
reqMap.put(&body&, WeiChartConfig.body);
//reqMap.put(&detail&, WeiChartConfig.subject); //非必填
//reqMap.put(&attach&, &附加数据&); //非必填
reqMap.put(&out_trade_no&, orderId); //商户系统内部的订单号,
reqMap.put(&total_fee&, totalFee); //订单总金额,单位为分
reqMap.put(&spbill_create_ip&, getHostIp()); //用户端实际ip
// reqMap.put(&time_start&, &172.16.40.18&); //交易起始时间 非必填
// reqMap.put(&time_expire&, &172.16.40.18&); //交易结束时间
// reqMap.put(&goods_tag&, &172.16.40.18&); //商品标记 非必填
reqMap.put(&notify_url&, WeiChartConfig.notify_url); //通知地址
reqMap.put(&trade_type&, &APP&); //交易类型
//reqMap.put(&limit_pay&, &no_credit&); //指定支付方式,no_credit 指定不能使用信用卡支
reqMap.put(&sign&, getSign(reqMap));
String reqStr = creatXml(reqMap);
String retStr = HttpClientUtil.postHttplient(WeiChartConfig.PrepayUrl, reqStr);
return getInfoByXml(retStr);
* 关闭订单
* @param orderId
商户自己的订单号
public static Map&String, String& closeOrder(String orderId){
Map&String, String& reqMap = new HashMap&String, String&();
reqMap.put(&appid&, WeiChartConfig.AppId);
reqMap.put(&mch_id&, WeiChartConfig.MchId);
reqMap.put(&nonce_str&, getRandomString());
reqMap.put(&out_trade_no&, orderId); //商户系统内部的订单号,
reqMap.put(&sign&, getSign(reqMap));
String reqStr = creatXml(reqMap);
String retStr = HttpClientUtil.postHttplient(WeiChartConfig.CloseOrderUrl, reqStr);
return getInfoByXml(retStr);
* 查询订单
* @param orderId 商户自己的订单号
public static String getOrder(String orderId){
Map&String, String& reqMap = new HashMap&String, String&();
reqMap.put(&appid&, WeiChartConfig.AppId);
reqMap.put(&mch_id&, WeiChartConfig.MchId);
reqMap.put(&nonce_str&, getRandomString());
reqMap.put(&out_trade_no&, orderId); //商户系统内部的订单号,
reqMap.put(&sign&, getSign(reqMap));
String reqStr = creatXml(reqMap);
String retStr = HttpClientUtil.postHttplient(WeiChartConfig.OrderUrl, reqStr);
return retS
* @param orderId
商户订单号
* @param refundId
* @param totralFee 总金额(分)
* @param refundFee 退款金额(分)
* @param opUserId 操作员ID
public static Map&String, String& refundWei(String orderId,String refundId,String totralFee,String refundFee,String opUserId){
Map&String, String& reqMap = new HashMap&String, String&();
reqMap.put(&appid&, WeiChartConfig.AppId);
reqMap.put(&mch_id&, WeiChartConfig.MchId);
reqMap.put(&nonce_str&, getRandomString());
reqMap.put(&out_trade_no&, orderId); //商户系统内部的订单号,
reqMap.put(&out_refund_no&, refundId); //商户退款单号
reqMap.put(&total_fee&, totralFee); //总金额
reqMap.put(&refund_fee&, refundFee); //退款金额
reqMap.put(&op_user_id&, opUserId); //操作员
reqMap.put(&sign&, getSign(reqMap));
String reqStr = creatXml(reqMap);
String retStr = &&;
retStr = HttpClientUtil.postHttplientNeedSSL(WeiChartConfig.RefundUrl, reqStr, WeiChartConfig.refund_file_path, WeiChartConfig.MchId);
}catch(Exception e){
e.printStackTrace();
return getInfoByXml(retStr);
* 退款查询
* @param refundId
public static Map&String, String& getRefundWeiInfo(String refundId){
Map&String, String& reqMap = new HashMap&String, String&();
reqMap.put(&appid&, WeiChartConfig.AppId);
reqMap.put(&mch_id&, WeiChartConfig.MchId);
reqMap.put(&nonce_str&, getRandomString());
reqMap.put(&out_refund_no&, refundId); //商户退款单号
reqMap.put(&sign&, getSign(reqMap));
String reqStr = creatXml(reqMap);
String retStr = HttpClientUtil.postHttplient(WeiChartConfig.RefundQueryUrl, reqStr);
return getInfoByXml(retStr);
生成头为XML的xml字符串,例:&xml&&key&123&/key&&/xml&
* @param reqMap
public static String creatXml(Map&String, String& reqMap){
Set&String& set = reqMap.keySet();
FXmlNode rootXml = new FXmlNode();
rootXml.setName(&xml&);
for(String key : set){
rootXml.createNode(key, reqMap.get(key));
return rootXml.xml().toString();
* 得到加密值
* @param map
public static String getSign(Map&String, String& map){
String[] keys = map.keySet().toArray(new String[0]);
Arrays.sort(keys);
StringBuffer reqStr = new StringBuffer();
for(String key : keys){
String v = map.get(key);
if(v != null && !v.equals(&&)){
reqStr.append(key).append(&=&).append(v).append(&&&);
reqStr.append(&key&).append(&=&).append(WeiChartConfig.AppSercret);
return RMd5.encode(reqStr.toString()).toUpperCase();
* 得到10 位的时间戳
* 如果在JAVA上转换为时间要在后面补上三个0
public static String getTenTimes(){
String t = new Date().getTime()+&&;
t = t.substring(0, t.length()-3);
* 得到随机字符串
* @param length
public static String getRandomString(){
int length = 32;
String str = &abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&;
Random random = new Random();
StringBuffer sb = new StringBuffer();
for(int i = 0; i & ++i){
int number = random.nextInt(62);//[0,62)
sb.append(str.charAt(number));
return sb.toString();
* 得到本地机器的IP
private static String getHostIp(){
String ip = &&;
ip = InetAddress.getLocalHost().getHostAddress();
}catch(UnknownHostException e){
e.printStackTrace();
* 将XML转换为Map 验证加密算法 然后返回
* @param xml
public static Map&String, String&
getInfoByXml(String xml){
FXmlDocument xdoc = new FXmlDocument();
FXmlNode nodeRoot = xdoc.formatStringToXml(xml);
FXmlNodes allNodes =
nodeRoot.allNodes();
Map&String, String& map = new HashMap&String, String&();
for(FXmlNode fXmlNode : allNodes){
map.put(fXmlNode.name(), fXmlNode.text());
//对返回结果做校验.去除sign 字段再去加密
String retSign = map.get(&sign&);
map.remove(&sign&);
String rightSing = getSign(map);
if(rightSing.equals(retSign)){
}catch(Exception e){
* 将金额转换成分
* @param fee 元格式的
* @return 分
public static String changeToFen(Double fee){
String priceStr = &&;
if(fee != null){
int p = (int)(fee * 100); //价格变为分
priceStr = Integer.toString(p);
return priceS
在微信支付的调试过程中,发现了一个困扰了很长时间的BUG,或者说是一个问题。
就是微信请求预支付的时候如果传了中文,就是body中给的是中文,就会报body不是UTF-8格式。如果强行对字段进行编码,又会报 加密错误。
但是这不是最主要的让人困扰的地方,最让我烦恼的是,我用本地的JDK调试的时候,它是OK 的。 但是用TOMCAT 部署的时候 却一直都不行
在网上有很多的说法,有的说,对body 进行编码转换UTF-8,有的说对整个请求的XML,进行编码。
还有的说编码格式用统一的。iso900…等等,巴拉巴拉的。。
反正我都不行。
最后在大神的帮助下,慢慢梳理,对发送请求的post方法上面想办法。
然后就是下面的 这句关键
public static String postHtpps(String urlStr,
String xmlInfo){
URL url = new URL(urlStr);
URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setRequestProperty(&Pragma:&, &no-cache&);
con.setRequestProperty(&Cache-Control&, &no-cache&);
con.setRequestProperty(&Content-Type&, &text/charset=utf-8&);
//在输入流里面进行转码,是最重要的
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(), &utf-8&);
out.write(xmlInfo);
out.flush();
out.close();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuffer lines = new StringBuffer();
String line = &&;
for(line = br.readLine(); line != line = br.readLine()){
lines.append(line);
return lines.toString();
}catch(MalformedURLException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
(C) Knowsky.comJavaWeb微信支付demo-开发-任务易推荐给您
JavaWeb微信支付demo
通过任务易推广注册的用户,完成该任务后可以获得 8元(80K币)的返利,
功能一:javaWeb网站浏览商品,发起支付请求,生成二维码,微信扫码完成支付.功能二:公众号浏览商品,发起支付请求,跳转h5页面完成支付.要求能跑通有相关注释,具体参数我都有,如果只能提供一个功能点也可,价钱另谈
任务易所有内容均为威客和外包行业网站提供或收集于互联网公开的信息,目的是给在网络上工作的威客和兼职人员收集更多的免费工作信息,以帮助更多的人自主就业。如果有内容触及您的权益,请给我们发邮件()并附上具体网址和说明,核实后我们将立即删除!对免责声明的解释、修改及更新权均属于任务易所有。
你觉得这个任务肿么样?
评分:3.5分
猪八戒网是全国最大的在线服务交易平台,由原《重庆晚报》首席记者朱明跃创办于2006年,服务交易品类涵盖创意设计、软件开发、网站建设、网络营销、文案策划、生活服务等多种行业。2011年猪八戒网获得IDG千万级美金投资,并被评选为中国2011年度“最佳商业模式十强”企业。2012年猪八戒还获得了国家文化产业示范基地称号。
你可能也对这些任务感兴趣
日内的任务

我要回帖

更多关于 java实现微信扫码支付 的文章

 

随机推荐