国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java接入內(nèi)購 Apple Pay、Google Play

這篇具有很好參考價(jià)值的文章主要介紹了Java接入內(nèi)購 Apple Pay、Google Play。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Java內(nèi)購接入Apple Pay、Google play

內(nèi)購流程:

  1. 客戶端向服務(wù)器發(fā)起請(qǐng)求生成預(yù)訂單,服務(wù)器校驗(yàn)后生成預(yù)訂單返回客戶端。若調(diào)起支付界面后未支付,則通知服務(wù)器取消本訂單。
  2. 客戶端拿到預(yù)訂單號(hào)后,在玩家完成付款操作后,攜帶預(yù)訂單號(hào)請(qǐng)求支付平臺(tái),將預(yù)訂單號(hào)存儲(chǔ)在支付平臺(tái)中,并獲取支付憑證。
  3. 客戶端攜帶支付憑證請(qǐng)求服務(wù)器,服務(wù)器攜帶支付憑證向支付平臺(tái)請(qǐng)求
  4. 服務(wù)器收到支付平臺(tái)的回值后,從回值中獲取訂單的支付狀態(tài)和預(yù)訂單號(hào),并通過預(yù)訂單號(hào)定位玩家具體購買的商品信息。
  5. 服務(wù)器返回客戶端校驗(yàn)信息,客戶端通知支付平臺(tái)本單已結(jié)束

內(nèi)購失敗處理方式:

  1. 校驗(yàn)失?。ňW(wǎng)絡(luò)波動(dòng),支付平臺(tái)狀態(tài)更新異常,玩家使用重復(fù)支付憑證)則先存儲(chǔ)校驗(yàn)時(shí)需要的參數(shù),例如,支付憑證,transactionId等信息,存儲(chǔ)在數(shù)據(jù)庫和ck中
  2. 在后臺(tái)中創(chuàng)建定時(shí),限次數(shù)的進(jìn)行后臺(tái)校驗(yàn)。重新攜帶參數(shù)請(qǐng)求支付平臺(tái),若校驗(yàn)通過,則通過郵件形式向玩家發(fā)郵件進(jìn)行補(bǔ)償。在達(dá)到校驗(yàn)最大次數(shù)后仍未通過校驗(yàn),則此單不再參與后臺(tái)自動(dòng)校驗(yàn)。
  3. 未通過校驗(yàn)的玩家可以通過聯(lián)系客服進(jìn)行再次校驗(yàn)??头梢酝ㄟ^遠(yuǎn)程腳本手動(dòng)查看支付平臺(tái)返回的校驗(yàn)信息,核實(shí)后向玩家發(fā)郵件補(bǔ)償,并手動(dòng)記錄在ck中。

客戶端邏輯:

客戶端先向支付平臺(tái)請(qǐng)求正在支付的列表,若存在未完成到訂單,則像服務(wù)器發(fā)送校驗(yàn)請(qǐng)求,直到服務(wù)器向客戶端返回信息,客戶端會(huì)向支付平臺(tái)發(fā)起結(jié)束本訂單的請(qǐng)求,完成完整的一次內(nèi)購。

校驗(yàn)代碼:

Apple Pay:
public AppleResponseData getIosOrderId(String transactionId, String url) {
    try {
      Map<String, Object> header = new HashMap<>();
      header.put("alg", "ES256");
      header.put("kid", new String(Base64.getDecoder().decode(iosKid.getBytes())));
      header.put("typ", "JWT");
      Map<String, Object> claims = new HashMap<>();
      claims.put("iss", new String(Base64.getDecoder().decode(iosIss.getBytes())));
      claims.put("iat",  Math.floor(System.currentTimeMillis() / 1000));
      claims.put("exp", Math.floor(System.currentTimeMillis() / 1000) + 1800);
      claims.put("aud", "appstoreconnect-v1");
      claims.put("bid", iosBid);
      //從p8文件獲取的秘鑰 此處為了方便演示直接使用的字符串,建議從p8文件中讀取,確保安全性
      String key = iosPrivateKey;

      PrivateKey privateKey = null;
      //ES256無法使用Base64加密的秘鑰來生成jwt 必須解碼
      KeyFactory kf = KeyFactory.getInstance("EC");
      privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(key)));
      //生成jwt
      String token = Jwts.builder()
          .setHeader(header)
          .setClaims(claims)
          .signWith(SignatureAlgorithm.ES256, privateKey)
          .compact();
      SSLContext sc = SSLContext.getInstance("SSL");
      sc.init(null, new TrustManager[]{new TrustAnyTrustManager()},
          new java.security.SecureRandom());
      URL console = new URL(url + transactionId);
      HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
      conn.setSSLSocketFactory(sc.getSocketFactory());
      conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
      conn.setRequestMethod("GET");
      conn.setRequestProperty("content-type", "text/json");
      conn.setRequestProperty("Proxy-Connection", "Keep-Alive");
      conn.setRequestProperty("Authorization", "Bearer "+ token);
      conn.setDoInput(true);
      conn.setDoOutput(true);
      conn.setConnectTimeout(3000);
      InputStream is = conn.getInputStream();
      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
      String line = "";
      StringBuilder sb = new StringBuilder();
      while ((line = reader.readLine()) != null) {
        sb.append(line);
      }
      JSONObject jsonObject = JSONObject.parseObject(sb.toString());
      LogUtil.trace("ios支付回值:" + jsonObject);
      String jwsTransactionBase64 = jsonObject.getString("signedTransactionInfo").split("\\.")[1];
      String jwsTransactionBase = new String(Base64.getDecoder().decode(jwsTransactionBase64));
      AppleResponseData appleResponseData = JSONObject.parseObject(jwsTransactionBase, new TypeReference<AppleResponseData>() {});
      return appleResponseData;
    } catch (Exception e) {
      CommonLogUtil.error(e.getMessage(), e);
    }
    return null;
  }

接收類:

public class AppleResponseData {

  //服務(wù)器uuid
  private String appAccountToken;

  //應(yīng)用包名
  private String bundleId;

  private String currency;

  //沙盒或者正式環(huán)境
  private String environment;

  //購買時(shí)間
  private long originalPurchaseDate;

  //產(chǎn)品id
  private String productId;

  //唯一標(biāo)識(shí)
  private String transactionId;
}

官方文檔: https://developer.apple.com/documentation/appstoreserverapi/get_transaction_history

需要參數(shù):

  1. transactionId:支付完成后客戶端從IOS平臺(tái)獲取的支付憑證。
  2. url:服務(wù)器校驗(yàn)地址,
    沙盒:https://api.storekitsandbox.itunes.apple.com/inApps/v1/transactions/ (+ transactionId)
    正式:https://api.storekit.itunes.apple.com/inApps/v1/history/ (+ transactionId)
  3. kid:密鑰id
  4. iss:issuer ID
  5. bid:應(yīng)用名稱,例如 com.company.production
  6. privateKey:已授權(quán)賬號(hào)在ios官網(wǎng)下載的p8文件中的內(nèi)容
    java服務(wù)端對(duì)接applepay,java,maven
Google Play:
public ProductPurchase googlePlayPayRequest(String productId, String purchaseToken,
      String packageName) {

    try {
      openTemProxy();
      List<String> scopes = new ArrayList<>();
      scopes.add(AndroidPublisherScopes.ANDROIDPUBLISHER);
      StringInputStream stringInputStream = new StringInputStream(new String(Base64.getDecoder().decode(googleVerifyJson)));
      GoogleCredential credential = GoogleCredential.fromStream(stringInputStream)
          .createScoped(scopes);
      //設(shè)置過期時(shí)間
      credential.setExpirationTimeMilliseconds(3000L);
      HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
      JsonFactory jsonFactory = new JacksonFactory();
      AndroidPublisher publisher = new AndroidPublisher.Builder(httpTransport, jsonFactory,
          credential).build();
      AndroidPublisher.Purchases purchases = publisher.purchases();
      final AndroidPublisher.Purchases.Products.Get request = purchases.products()
          .get(packageName, productId, purchaseToken);
      return request.execute();
    } catch (Exception e) {
      LogUtil.info(e.getMessage(), e);
    } finally {
      Properties systemProperties = System.getProperties();
      if(openProxy){
        systemProperties.clear();
      }
    }
    return null;
  }

  /**
  * 開啟代理
  */
  public void openTemProxy() {
    if(true){
      //代理端口
      try {
        Properties systemProperties = System.getProperties();
        systemProperties.setProperty("http.proxyHost", "127.0.0.1");
        systemProperties.setProperty("http.proxyPort", "7890");
        systemProperties.setProperty("https.proxyHost", "127.0.0.1");
        systemProperties.setProperty("https.proxyPort", "7890");
        systemProperties.setProperty("socksProxyHost", "127.0.0.1");
        systemProperties.setProperty("socksProxyPort", "7890");
        systemProperties.setProperty("http.nonProxyHosts", "localhost");
        systemProperties.setProperty("https.nonProxyHosts", "localhost");

      } catch (Exception e) {
        CommonLogUtil.error(e.getMessage(), e);
      }
    }
  }

maven:

	<dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-androidpublisher</artifactId>
      <version>v3-rev24-1.24.1</version>
    </dependency>

    <dependency>
      <groupId>com.google.auth</groupId>
      <artifactId>google-auth-library-oauth2-http</artifactId>
      <version>1.3.0</version>
    </dependency>

官方文檔: https://developers.google.cn/android-publisher/api-ref/rest/v3/purchases.products?skip_cache=true&hl=zh-cn

需要參數(shù):

  1. productId: 產(chǎn)品id
  2. purchaseToken: 購買憑證
  3. packageName: 項(xiàng)目名稱
  4. verifyJson: google后臺(tái)獲取授權(quán)賬號(hào)json文件

google授權(quán)文檔: https://www.quicksdk.com/doc-516.html文章來源地址http://www.zghlxwxcb.cn/news/detail-853812.html

到了這里,關(guān)于Java接入內(nèi)購 Apple Pay、Google Play的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Unity接入IAP內(nèi)購(Android,IOS)最新流程,第一篇:內(nèi)購接入

    Unity接入IAP內(nèi)購(Android,IOS)最新流程,第一篇:內(nèi)購接入

    你好! 這將是一個(gè)系列的文章 第一篇 介紹客戶端里支付的調(diào)起以及購買。 第二篇 介紹后臺(tái)對(duì)購買結(jié)果的驗(yàn)證以及發(fā)貨(IOS)。 第三篇 介紹后臺(tái)對(duì)購買結(jié)果的驗(yàn)證以及發(fā)貨(Android)。 第四篇 介紹后臺(tái)對(duì)內(nèi)購?fù)藛螁栴}的處理(IOS欺詐檢測(cè)以及欺詐信息反饋)。 我們是用的

    2024年04月13日
    瀏覽(21)
  • Unity接入IAP、服務(wù)器驗(yàn)單(Google Play)

    Unity接入IAP、服務(wù)器驗(yàn)單(Google Play)

    最近因?yàn)轫?xiàng)目需要,被分配來做項(xiàng)目SDK接入以及上架相關(guān)事宜。搞了好幾天關(guān)于Unity接入支付的SDK,接入很簡單,卡的最久的就是服務(wù)器驗(yàn)單,google相關(guān)文檔也不是很全,走通之后覺得可以發(fā)出來共享一下,第一次寫文章,有什么不足多多見諒 Unity已經(jīng)集成了Google Pay、Apple

    2023年04月11日
    瀏覽(27)
  • Unity 之 接入IOS內(nèi)購過程解析【文末源碼】

    Unity 之 接入IOS內(nèi)購過程解析【文末源碼】

    看完此文章你可以了解IOS內(nèi)購接入全過程,可以學(xué)習(xí)到Unity從零接入內(nèi)購功能。另外此博文和文末源碼沒有涉及到掉單補(bǔ)單部分邏輯。 一臺(tái)mac系統(tǒng)機(jī)器 蘋果開發(fā)者賬號(hào) Unity2019.4.x (不同版本,3步驟略有不同) Xcode (我的版本12.5) PS:若公司已有運(yùn)營人員在后臺(tái)操作過了,可以

    2023年04月17日
    瀏覽(16)
  • 【Unity】Unity接入內(nèi)購IAP,提示you are not authorized to set the license key

    【Unity】Unity接入內(nèi)購IAP,提示you are not authorized to set the license key

    接入IAP的時(shí)候需要輸入谷歌的開發(fā)者后臺(tái)key Unity2020之后有可能會(huì)提示:you are not authorized to set the license key 查閱相關(guān)內(nèi)容后(https://forum.unity.com/threads/purchase-you-are-not-authorized-to-set-the-license-key-google-play.954261/) Unity2020后不在Editor上面填寫了,改成在Dashboard上輸入 打開后輸入即

    2024年02月08日
    瀏覽(26)
  • Apple Unity Plugins 接入GameCenter 崩潰解決方案

    Apple Unity Plugins 接入GameCenter 崩潰解決方案

    調(diào)用 GKLocalPlayer.Local.FetchItems() 程序崩潰,報(bào)錯(cuò): Thread 1: EXC_BAD_ACCESS (code=257, address=0x8000000000000002) 啟動(dòng)崩潰,報(bào)錯(cuò): Library not loaded: @rpath/AppleCoreNative.framework/AppleCoreNative 蘋果官方提供的庫,直接編譯后,會(huì)在調(diào)用 GKLocalPlayer.Local.FetchItems() 時(shí)崩潰。 https://github.com/apple/unityplu

    2024年01月16日
    瀏覽(25)
  • 安卓接入Google登錄

    安卓接入Google登錄

    目錄 1.配置Google Cloud 2.添加 Google Play 服務(wù) 3.添加Google sign代碼 4.常見的CommonStatusCodes 后補(bǔ)Web clien(Auto-created for Google Sign-in)由來 ? ? ? ? 首先要在 Google Cloud?中創(chuàng)建一個(gè)項(xiàng)目。左側(cè)菜單-API和服務(wù)-憑據(jù)。進(jìn)入之后先配置同意屏幕。 ? 填寫必必要的信息,應(yīng)用名稱、用戶支持電子

    2024年02月01日
    瀏覽(19)
  • Unity接入Google登錄,踩坑

    記錄不明坑 根據(jù)大佬們寫的文章Unity接入Google登錄超詳細(xì)流程接入Google,但是在導(dǎo)入安卓依賴管理插件EDM4U后,卻瘋狂報(bào)錯(cuò)。 剛開始是: Assembly \\\'Assets/ExternalDependencyManager/Editor/Google.VersionHandlerImpl_v1.2.157.dll\\\' will not be loaded due to errors: Assembly name \\\'Google.VersionHandlerImpl\\\' does not matc

    2024年02月05日
    瀏覽(20)
  • ios swift5 “Sign in with Apple“(使用蘋果登錄)怎樣接入(第三方登錄)集成AppleID登錄

    ios swift5 “Sign in with Apple“(使用蘋果登錄)怎樣接入(第三方登錄)集成AppleID登錄

    1.1 如果你新建app id,記得在新建的時(shí)候就選中Sign in with Apple功能 1.2 如果app已經(jīng)上線了,后面再需要加蘋果登錄的功能,也可以在app id的配置中加這個(gè)功能,只是勾選Sign in with Apple點(diǎn)擊Save后,profilex需要重新生成 iOS 蘋果登錄(第三方登錄) - csdn 集成AppleID登錄 - 簡書 要在你的

    2024年04月09日
    瀏覽(38)
  • Unity接入Google登錄超詳細(xì)流程

    Unity接入Google登錄超詳細(xì)流程

    1、unity版本:2021.3.21f1 特別說明:通過Unityhub安裝的Unity,需要安裝對(duì)應(yīng)版本所需的JDK、SDK、NDK,我們默認(rèn)使用Unity自帶的,不需要使用自己下載的,否則可能會(huì)導(dǎo)致打包失敗的問題。 2、google登錄sdk版本:GoogleSignIn_v1.0.4.1 特別說明: (1)GoogleSignIn官方插件地址是:GoogleSignIn,但

    2024年02月09日
    瀏覽(24)
  • 安卓接入google的Firebase登錄教程

    安卓接入google的Firebase登錄教程

    1.https://console.firebase.google.com創(chuàng)建安卓項(xiàng)目? ?? ? ? ? ? ? ? 2.添加google登錄 ? ? ? ? ? ? ?3.添加項(xiàng)目的SHA證書指紋 ? ? ? ? ?? ? ? ? ? ?? 4. FireBase自動(dòng)生成(API和服務(wù))? ?https://console.cloud.google.com/apis/credentials?authuser=1project=battle-against-darkness ? ? ? ? ?? 5.下載google-s

    2024年01月21日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包