锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

Facebook支付

时间:2022-12-21 13:00:00 ogp301光电传感器

html

doctype html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">     <meta http-equiv="X-UA-Compatible" content="ie=edge">     <title>Loading...title> head> <body> <div id="fb-root">div> <script> var appid = 你的应用编号; var product = '{$product}'; // 产品信息页面地址 var request_id = '{$request_id}'; //订单的id,必须是唯一的 var callbackurl = '{$callbackurl}'; 
         
          // 回调地址
          window.fbAsyncInit = function() { 
          FB.init({ 
          appId : appid, status : true, cookie : true, xfbml : true, version: 'v3.2' // 使用图形api v3.2版本 }); function FacebookCreditsOrder() { 
          var obj = { 
          method: 'pay', action: 'purchaseitem', product: product,//产品信息页面的地址 request_id: request_id,//订单的id,必须是唯一的 }; FB.ui(obj, function(data) { 
          console.log(data); if( data['status'] == 'completed'){ 
          bh_msg_tips('Transaction Completed!') }else{ 
          bh_msg_tips('Transaction Failed!') } setTimeout(function () { 
          window.location.href = callbackurl; },1500) }); } FacebookCreditsOrder(); }; // Load the SDK Asynchronously (function(d){ 
          var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) { 
          return; } js = d.createElement('script'); js.id = id; js.async = true; js.src = "https://connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); // 页面提示信息 function bh_msg_tips(msg){ 
          var oMask = document.createElement("div"); oMask.id = "bh_msg_lay"; oMask.style.position="fixed"; oMask.style.left="0"; oMask.style.top="70%"; oMask.style.zIndex="100"; oMask.style.textAlign="center"; oMask.style.width="100%"; oMask.innerHTML = "" + msg + ""; document.body.appendChild(oMask); setTimeout(function(){ 
         $("#bh_msg_lay").remove();},2000); } script>
body>
html>

产品信息页面的地址

DOCTYPE html>
<html>
 <head prefix= "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# product: http://ogp.me/ns/product#">
    <meta property="og:type" content="og:product" />
    <meta property="og:title" content="100 Coin Pack" />
    <meta property="og:image" content="/images/coin_bundle64.png" />
    <meta property="og:description" content="A hundred coins!" />
    <meta property="og:url" content="/payments/100coins.html" />
    <meta property="product:price:amount" content="2.99"/>
    <meta property="product:price:currency" content="USD"/>
    <meta property="product:price:amount" content="1.99"/>
    <meta property="product:price:currency" content="GBP"/>
 head>
html>

回调

 // facebook 支付回调
    function facebook(){ 
        
        $verify_token = "ssdfshhngthkouyk";
        $hub_challenge = $_GET['hub_challenge'];
        $hub_verify_token = _GET['hub_verify_token'];
        if ($hub_verify_token === $verify_token) { 
        
            return $hub_challenge;
        }

        // 更新订单信息
        $data = file_get_contents("php://input");
        $json = json_decode($data,true);
        add_error_log('支付结果回调',$data);
        if( isset($json["object"]) && $json["object"] && $json["object"] == "payments" ) { 
        
            $payment_id = $json["entry"][0]["id"];

            $fb = new Facebook([
                'app_id' => '你的应用编号',
                'app_secret' => '你的秘钥',
                'default_graph_version' => 'v3.2',
            ]);
            $result = $fb->get($payment_id . '?fields=user,actions,request_id,items,gift_requests', config('app_token'));
            $result = json_decode($result->getBody(), true);
            $actions = isset($result['actions'][0]) ? $result['actions'][0] : [];
            $request_id = isset($result['request_id']) ? $result['request_id'] : '';
            if ($actions['status'] == 'completed' && !empty($request_id)) { 
        
                // 处理订单信息
            }
        }

    }
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章