91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java中怎么實現微信支付功能

發布時間:2021-08-09 16:39:42 來源:億速云 閱讀:114 作者:Leah 欄目:編程語言

這篇文章將為大家詳細講解有關java中怎么實現微信支付功能,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

具體內容如下

package com.fengdi.lianmeng.zhifu.weixin;import com.fengdi.lianmeng.util.MD5;import java.lang.reflect.Field;import java.util.HashMap;import java.util.Map;/** *  * 類說明:除被掃支付場景以外,店鋪系統先調用該接口在微信支付服務后臺生成預支付交易單, * 返回正確的預支付交易回話標識后再按掃碼、JSAPI、APP等不同場景生成交易串調起支付。 * @author 聶楓 * 2016年1月8日上午11:33:21 */public class UnifiedorderReq{ /** * 公眾賬號ID */ private String appid; /** * 店鋪號 */ private String mch_id; /** * 設備號 */ private String device_info; /** * 隨機字符串 */ private String nonce_str; /** * 簽名 */ private String sign; /** * 商品描述 */ private String body; /** * 商品詳情 */ private String detail; /** * 附加數據 */ private String attach; /** * 店鋪訂單號 */ private String out_trade_no; /** * 貨幣類型 */ private String fee_type; /** * 總金額 */ private Integer total_fee; /** * 終端IP */ private String spbill_create_ip; /** * 交易起始時間 */ private String time_start; /** * 交易結束時間 */ private String time_expire; /** * 商品標記 */ private String goods_tag; /** * 通知地址 */ private String notify_url; /** * 交易類型 */ private String trade_type; /** * 商品ID */ private String product_id; /** * 指定支付方式 */ private String limit_pay; /** * 用戶標識 */ private String openid; public String getAppid() { return appid; } public void setAppid(String appid) { this.appid = appid; } public String getMch_id() { return mch_id; } public void setMch_id(String mch_id) { this.mch_id = mch_id; } public String getDevice_info() { return device_info; } public void setDevice_info(String device_info) { this.device_info = device_info; } public String getNonce_str() { return nonce_str; } public void setNonce_str(String nonce_str) { this.nonce_str = nonce_str; } public String getSign() { return sign; } public void setSign(String sign) { this.sign = sign; } public String getBody() { return body; } public void setBody(String body) { this.body = body.length()>40?body.substring(0, 40):body; } public String getDetail() { return detail; } public void setDetail(String detail) { this.detail = detail; } public String getAttach() { return attach; } public void setAttach(String attach) { this.attach = attach; } public String getOut_trade_no() { return out_trade_no; } public void setOut_trade_no(String out_trade_no) { this.out_trade_no = out_trade_no; } public String getFee_type() { return fee_type; } public void setFee_type(String fee_type) { this.fee_type = fee_type; } public Integer getTotal_fee() { return total_fee; } public void setTotal_fee(Integer total_fee) { this.total_fee = total_fee; } public String getSpbill_create_ip() { return spbill_create_ip; } public void setSpbill_create_ip(String spbill_create_ip) { this.spbill_create_ip = spbill_create_ip; } public String getTime_start() { return time_start; } public void setTime_start(String time_start) { this.time_start = time_start; } public String getTime_expire() { return time_expire; } public void setTime_expire(String time_expire) { this.time_expire = time_expire; } public String getGoods_tag() { return goods_tag; } public void setGoods_tag(String goods_tag) { this.goods_tag = goods_tag; } public String getNotify_url() { return notify_url; } public void setNotify_url(String notify_url) { this.notify_url = notify_url; } public String getTrade_type() { return trade_type; } public void setTrade_type(String trade_type) { this.trade_type = trade_type; } public String getProduct_id() { return product_id; } public void setProduct_id(String product_id) { this.product_id = product_id; } public String getLimit_pay() { return limit_pay; } public void setLimit_pay(String limit_pay) { this.limit_pay = limit_pay; } public String getOpenid() { return openid; } public void setOpenid(String openid) { this.openid = openid; } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("UnifiedorderReq [appid="); builder.append(appid); builder.append(", mch_id="); builder.append(mch_id); builder.append(", device_info="); builder.append(device_info); builder.append(", nonce_str="); builder.append(nonce_str); builder.append(", sign="); builder.append(sign); builder.append(", body="); builder.append(body); builder.append(", detail="); builder.append(detail); builder.append(", attach="); builder.append(attach); builder.append(", out_trade_no="); builder.append(out_trade_no); builder.append(", fee_type="); builder.append(fee_type); builder.append(", total_fee="); builder.append(total_fee); builder.append(", spbill_create_ip="); builder.append(spbill_create_ip); builder.append(", time_start="); builder.append(time_start); builder.append(", time_expire="); builder.append(time_expire); builder.append(", goods_tag="); builder.append(goods_tag); builder.append(", notify_url="); builder.append(notify_url); builder.append(", trade_type="); builder.append(trade_type); builder.append(", product_id="); builder.append(product_id); builder.append(", limit_pay="); builder.append(limit_pay); builder.append(", openid="); builder.append(openid); builder.append("]"); return builder.toString(); }  public String toSignString(){ Class<?> clz = this.getClass(); Field[] fields = clz.getDeclaredFields(); StringBuilder builder = new StringBuilder(); for (Field field : fields) {  builder.append(field.getName()); } return builder.toString(); }  public String signString(){ StringBuilder builder = new StringBuilder(); builder.append("appid="+appid); if(attach!=null){  builder.append("&attach="+attach); } builder.append("&body="+body); builder.append("&mch_id="+mch_id); builder.append("&nonce_str="+nonce_str); builder.append("&notify_url="+notify_url); if(!trade_type.equals("APP")) {  builder.append("&openid="+openid); } builder.append("&out_trade_no="+out_trade_no); builder.append("&spbill_create_ip="+spbill_create_ip); builder.append("&total_fee="+total_fee); builder.append("&trade_type="+trade_type); builder.append("&key="+FgWxConfig.mobilekey); return builder.toString(); }  public String wapSignString(){ StringBuilder builder = new StringBuilder(); builder.append("appid="+appid); if(attach!=null){  builder.append("&attach="+attach); } builder.append("&body="+body); builder.append("&mch_id="+mch_id); builder.append("&nonce_str="+nonce_str); builder.append("&notify_url="+notify_url); if(!trade_type.equals("APP")) {  builder.append("&openid="+openid); } builder.append("&out_trade_no="+out_trade_no); builder.append("&spbill_create_ip="+spbill_create_ip); builder.append("&total_fee="+total_fee); builder.append("&trade_type="+trade_type); builder.append("&key="+FgWxConfig.key); return builder.toString(); }  public String toXml(){ return "<xml>" +      "<appid>"+appid+"</appid>"+      (attach != null? "<attach>"+attach+"</attach>" : "")+         "<body>"+body+"</body>"+         "<mch_id>"+mch_id+"</mch_id>"+         "<nonce_str>"+nonce_str+"</nonce_str>"+         "<notify_url>"+notify_url+"</notify_url>"+         (trade_type.equals("APP") == true?"":"<openid>"+openid+"</openid>")+         "<out_trade_no>"+out_trade_no+"</out_trade_no>"+         "<spbill_create_ip>"+spbill_create_ip+"</spbill_create_ip>"+         "<total_fee>"+total_fee+"</total_fee>"+         "<trade_type>"+trade_type+"</trade_type>"+         "<sign>"+MD5.encryptByMD5(signString()).toUpperCase()+"</sign>"+         "</xml>"; }  public String toWapXml(){ return "<xml>" +      "<appid>"+appid+"</appid>"+      (attach != null? "<attach>"+attach+"</attach>" : "")+         "<body>"+body+"</body>"+         "<mch_id>"+mch_id+"</mch_id>"+         "<nonce_str>"+nonce_str+"</nonce_str>"+         "<notify_url>"+notify_url+"</notify_url>"+         (trade_type.equals("APP") == true?"":"<openid>"+openid+"</openid>")+         "<out_trade_no>"+out_trade_no+"</out_trade_no>"+         "<spbill_create_ip>"+spbill_create_ip+"</spbill_create_ip>"+         "<total_fee>"+total_fee+"</total_fee>"+         "<trade_type>"+trade_type+"</trade_type>"+         "<sign>"+MD5.encryptByMD5(wapSignString()).toUpperCase()+"</sign>"+         "</xml>"; }  /*支付查詢簽名字符串*/ public String signQueryString(String transaction_id){ StringBuilder builder = new StringBuilder(); builder.append("appid="+appid); builder.append("&body="+body); builder.append("&mch_id="+mch_id); builder.append("&nonce_str="+nonce_str); builder.append("&transaction_id="+transaction_id); builder.append("&key="+FgWxConfig.mobilekey); return builder.toString(); }  /*支付查詢*/ public String toQueryXml(String transaction_id){ StringBuilder sBuilder=new StringBuilder(); sBuilder.append("<xml>"); sBuilder.append("<appid>"+appid+"</appid>"); sBuilder.append("<body>"+body+"</body>"); sBuilder.append("<mch_id>"+mch_id+"</mch_id>"); sBuilder.append("<nonce_str>"+nonce_str+"</nonce_str>"); sBuilder.append("<transaction_id>"+transaction_id+"</transaction_id>"); sBuilder.append("<sign>"+MD5.encryptByMD5(signQueryString(transaction_id)).toUpperCase()+"</sign>"); sBuilder.append("</xml>"); return sBuilder.toString(); }  public Map<String,Object> toMap(){ Map<String, Object> params = new HashMap<String, Object>(); params.put("appid", appid); if(attach!=null){  params.put("attach", attach); } params.put("body", body); params.put("mch_id", mch_id); params.put("nonce_str", nonce_str); params.put("notify_url", notify_url); if(!trade_type.equals("APP")) {  params.put("openid", openid); } params.put("out_trade_no", out_trade_no); params.put("spbill_create_ip", spbill_create_ip); params.put("total_fee", total_fee); params.put("trade_type", trade_type); params.put("sign", MD5.encryptByMD5(signString()).toUpperCase()); return params; }

組裝工具類數據

private AppWeixinPayResponse appUnifiedorderReq(Order order, Member member, HttpServletRequest request) {    // 獲取支付參數    UnifiedorderReq unifiedorderReq = new UnifiedorderReq();    unifiedorderReq.setBody(order.getOrderName().length() > 50 ? order.getOrderName().substring(0, 50) : order.getOrderName());    log.error(unifiedorderReq.getBody().length() + "--" + unifiedorderReq.getBody());    unifiedorderReq.setAttach(order.getOrderNo());    unifiedorderReq.setTotal_fee(order.getRealAmt().intValue());    unifiedorderReq.setTrade_type("APP");//此處可修改為JSAPI    unifiedorderReq.setOut_trade_no(order.getOrderNo() + RandomUtils.nextInt(100, 1000));    unifiedorderReq.setSpbill_create_ip(getIpAddr(request));    unifiedorderReq.setOpenid(member.getOpenid());    return payService.appUnifiedorderReq(unifiedorderReq, PayCategory.order.toString());  }

微信統一下單

public AppWeixinPayResponse appUnifiedorderReq(UnifiedorderReq unifiedorderReq, String payCategory)  throws FdServiceException { unifiedorderReq.setAppid(FgWxConfig.appid_app); unifiedorderReq.setMch_id(FgWxConfig.mchId); unifiedorderReq.setNonce_str(Random2Utils.generateString(20)); if (payCategory.equals(PayCategory.order.toString())) {  unifiedorderReq.setNotify_url(fgProperties.getDomainUrl() + FgWxConfig.weixinOrderNotifyCallBack); } else if (payCategory.equals(PayCategory.recharge.toString())) {  unifiedorderReq.setNotify_url(fgProperties.getDomainUrl() + FgWxConfig.weixinRechargeNotifyCallBack); } else {  throw new FdServiceException(ErrorCode.ILLEGAL_ARGUMENT, "微信參數類型[" + payCategory + "]異常"); } unifiedorderReq.setSign(MD5.encryptByMD5(unifiedorderReq.wapSignString()).toUpperCase()); logger.info("unifiedorder返回數據unifiedorderReq:" + unifiedorderReq); String unifiedorder = FgHttp.sendPost(FgWxConfig.unifiedorderUrl, unifiedorderReq.toWapXml()); logger.info("unifiedorder返回數據unifiedorder:" + unifiedorder); AppWeixinPayResponse appWeixinPayResponse = new AppWeixinPayResponse(); try {  Map<String, Object> map = XmlHelper.parseResXML(unifiedorder);  if ("SUCCESS".equals(map.get("return_code")) && "SUCCESS".equals(map.get("result_code"))) {  logger.info("微信統一下單返回成功:" + map);  appWeixinPayResponse.setAppid(FgWxConfig.appid_app);  appWeixinPayResponse.setNoncestr((String) map.get("nonce_str"));  appWeixinPayResponse.setPartnerid(FgWxConfig.mchId);  appWeixinPayResponse.setPrepayid((String) map.get("prepay_id"));  appWeixinPayResponse.setTimestamp((System.currentTimeMillis() + "").substring(0, 10));  appWeixinPayResponse.setSign(MD5.encryptByMD5(appWeixinPayResponse.wapSignString()).toUpperCase());  } else {  logger.info("微信統一下單返回失敗:" + map);  throw new FdServiceException(ErrorCode.ILLEGAL_ARGUMENT, "微信統一下單返回失敗:" + map.get("return_msg"));  } } catch (IOException e) {  e.printStackTrace(); } catch (ParserConfigurationException e) {  e.printStackTrace(); } catch (SAXException e) {  e.printStackTrace(); } return appWeixinPayResponse;//直接將參數返回給前端,發起支付 }

關于java中怎么實現微信支付功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

华宁县| 集安市| 团风县| 金山区| 富锦市| 彰化市| 德阳市| 太仆寺旗| 杭锦后旗| 宕昌县| 红安县| 鄂温| 永新县| 武威市| 湖南省| 石河子市| 繁昌县| 茶陵县| 贡嘎县| 大厂| 科技| 台东县| 沙田区| 新疆| 出国| 银川市| 威信县| 泌阳县| 信丰县| 陵川县| 库尔勒市| 武功县| 慈利县| 政和县| 珲春市| 扎兰屯市| 昌宁县| 宁海县| 洛浦县| 临安市| 龙川县|