WeChatの支払いにJSAPIを使用するには、最初にWeChatからPrepay_idを取得し、JS APIの返品結果はget_brand_wcpay_request:okのみがユーザーが支払いを完了したときのみです。複雑なフロントエンドインタラクティブインタラクションのため、get_brand_wcpay_request:cancelまたはget_brand_wcpay_request:失敗は、ユーザーがエラーに遭遇したり、積極的にあきらめたりするために均一に処理できます。
例コードは次のとおりです。
function onbridgeready(){weixinjsbridge.invoke( 'getbrandwcpayrequest'、{"appid": "" wx2421b1c4370ec43b "、//パブリックアカウントの名前は「タイムスタンプ」:" 139 "5712654"、1970年以降、 "139" 5712654 "に渡されました。 「非cestr」: "e61463f8efa94090b1f366ccfbbbb444"、//随机串 "パッケージ": "u802345jgfjsdfgsdg888"、 "signtype": "md5"、/// 4c63ff7fadd89 "//微信签名}、function( res){if(res.err_msg == "get_brand_wcpay_request:ok"){} //上記の方法を使用してフロントエンドのリターンを決定します。しかし、それはそれを保証しません。 ); document.attachevent( 'onweixinjsbridgeready'、onbridgeready);
パラメーターパッケージの上記のパラメーターはprepaay_idです
以下は、JSAPIを呼び出すパラメーターを取得することについてです
JSAPIに電話するときは、ユーザーのOpenIDを取得する必要があります。
最初にリクエストのオブジェクトを定義します。
com.protpedable.unstopped.httpservice。 java.util.map文字列式= builder.device_info; .out_trade_type.fee_type; builder.goods_tag ify_url void setAppid(string appid)= appid;} public void setmch_id(string mch_id){this .mch_id = mch_id;} public void setdevice_info(string device_info){this.device_info = divice_info;} public void setnonononce_str r){nonce_str r) nonce_str;} public void setsign(string sign){this.sign = sign;} public void body(this.body = body;} public void setdetail(this.detail = detail;} public Voice ch(string attach){this.attach = attach;} public void setout_trade_no(string out_trade_no){this.out_trade_no = out_trade_no;} public void setfee_type(string fee_type){this.fee_type = fee_type;} pubr ic void settotal_fee( ) {This.total_fee = Total_fee;} Public void Setspbill_Create_ip (String SPBILL_CREATE_IP) {This .spbill_create_ip = spban_create_ip;} Public void settime_start (string time_start) {this.time_start = time_start; String time_expire) {this.time_expire = time_expire;} public void setgoods_tags (string goods_tag) {this.goods_tags_tag; } PUBLIC VOID SETNOTIFY_URL (String Notify_url) {this.notify_url = notify_url;} Public void Settrade_Type (String Trade_type) {This.tr Ade_type = Trade_type;} Public Void SetProduct_id (String Product_id) {this.product_id = product_id;} public void setlimit_pay(string limit_pay){this.limit_pay = limit_pay;} public void setopenid(string openid){this.openid;} public map <string> object> tom> ap() {Map <String> Map <string、object field = this.getClass(); .get(this); if(obj!= null){map.put(field.getname()、obj);}} catch(e.printstacktrace();} catch(legalaccessexception e){acece ();} public static class requid appid { Private Spbill_ipパラメーターappidを渡すことはnull ");} if(mch_id == null){newAlargumentException(" "MCH_IDの数字はnull") null ");} if(out_trade_no == null){throw newalargumentexception numbers out_trade_noはnull") == null){throw newAlargumentException( "パラメーターの数spbill_create_ipの数はnull") )de_typeはnull ");} this.appid; this .mch_id = mch_id; this.body = body; this.out_trade_no = out_trade_no; total_fee; ate_ip; thise_ip; this.notify_url = notify_url; this.trade_type = trade_type;} public unifyreqdatabuilder setDevice_info){this.device_info = device_info;これを返します= time_expire; imit_pay = limit_pay ; ILLEGALAGUMENTEXCEPTION( "Trade_TypeがJSAPIである場合、OpenIDは必須パラメーターです。 fill parameter ");} new unifidordorderreqdata(this);}}}}}を返す必要があります。
一部のパラメーターが必要なため、一部のパラメーターが選択されます。また、計算する前にすべてのパラメーターが渡されるのを待つ必要があるため、ここでビルダーモードが使用されます。ビルダーモードについて。
ネットワーク伝送用のhttpclientを選択します。
com.xtream.xstream.xstream.io.domdriver。ログlog.httpetity .apache.http.config.http.client.httpget; ConnectionPoolUtexception。 http.httpclients Java.security.keystoreタイムアウト時間、デフォルトのプライベートStatic int sockettimeout = 5000; keystore = keystore.getInstance( "pkcs12"); fileinputStream enteam = new fileinputStream(configure.getCertLocalPath()); sslcontexts.custom().loadkeymaterial(keystore、configure.getcertpassword()。tocharray()。ild(); // sslconnectionsocketactoryのみsslsf = new sslconnectionsottactory(sslcontext、new String [] null [] 'tlsv1 " sslconnectionsotfactory.browser_compatible_hostname_verifier); requestconfig config =) (sslsf).build(); {new runtimee xception( "エラーCreate httpclient ..."、e);}} public static string doget(string requesturl)スロー{httpget httpget = new httpget(requesturl); GetRequestLine()); GetStatusCode();ステータス: " + status);}}}; return httpclient.execute(httpget、responsehandler);}最後に{httpget.releaseconnection();}} public stric string vopost(string url、object object2xml){string result = null; = new httppost(url); APIに提出されたのは、XMLフォーマットに変換されます-8エンコーディング、それ以外の場合は、APIサーバーの中国語を正常に識別できません。 ;/ configuration logger.info "execting" + httppost.getRequestline();エンティティ、 "utf-8");} catch(connectionpooltimeoutexception e){logger.error( "http get connectionpooltimeoutexception(wait time out)"、e);} catch event e){logger.error( "http get thnecttimeoutexception "、e);} catch){logger.error(" "http get shockettimeoutexception"、e);} catch(exception e){logger.error( "http get show)、e);}最後に{httppp ost。 abort();} return result;
それから私たちの一般的な入り口があります:
com.unstopped.Common.httpsersのパッケージParserconfigurationexception; Import java.util.map; IOException、saxexception、parserconfigutexception {string res)onfigure.unified_order_api、reqdata); 「 、 "mch_id"、 "out_trade_no"、1、 "spaby_create_ip_ip_ip_ip_ip"、notify_url "、" jsapi ")。setopenid(" openid ")。
返されたXMLは次のとおりです。
<xml> <sturn_code> < cdata [10000100]> </mch_id> <nonce_str> < 7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d7d76d7d7d7d7d7d76d7d7d7d7d7d7d7d76d7d7d7d7d7d76d7d7d7d7d76d76d7d7d7e86d7e8d75e8e8e8e8e8e8e8e8e8 _code> <![cdata [success]> </result_code> <prepay_id> <
return_codeとresult_codeが成功したときにprepay_idを返します。エッセンスエッセンス、その後、Jsapiで彼を使用します。エッセンス
この記事は、「JavaScript Wechat Development Summary」、「Android Wechat Development Tutorial Summary」、および「Java Wechat Development Tutorial Summary」に整理されています。
すべての人に注意を払ったWechat Miniプログラムのチュートリアルをお勧めします。
上記は、この記事のすべての内容です。