微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Nodejs 将通行证保存到 Google Pay?

如何解决如何使用 Nodejs 将通行证保存到 Google Pay?

我想将 google pay API 用于具有 firebase 云功能的通行证,但不幸的是,nodejs 在 google-pay/passes-rest-samples 中被严重遗漏,并且在 client libraries 中不受支持

我能够在 PHP 示例中测试 API - 即我的服务帐户已启动并链接到我的商家帐户,但我想知道如何在 nodejs 中使用该 API:

1- 如何在请求调用获取访问令牌并保存传递?

尝试了以下操作,但我总是收到 401 状态代码

a) 使用 google-auth-library-nodejs

    // Create a new JWT client using the key file downloaded from the Google Developer Console
      const auth = new google.auth.GoogleAuth({
          keyFile: path.join(__dirname,'serviceAccount.json'),scopes: 'https://www.googleapis.com/auth/wallet_object.issuer',});
      const client = await auth.getClient();
      const accesstoken = (await client.getAccesstoken()).token;

      const result = (await axios.post(`https://walletobjects.googleapis.com/walletobjects/v1/loyaltyClass?strict=true`,payload,{ headers: { Authorization: `Bearer ${accesstoken}` } })
    ).data;
     

b) 使用 jsonwebtoken

 const token = jwt.sign({ payload,typ: JWT_TYPE },credentialJson.private_key,{
            algorithm: 'RS256',audience: AUDIENCE,issuer: SERVICE_ACCOUNT_EMAIL_ADDRESS,});

解决方法

以下是如何使用 Node.js 实现这一目标的example

相关部分:

function mytheme_customize_register( $wp_customize ) {
    //All our sections,settings,and controls will be added here
    $wp_customize->add_setting( 'link-color',array(
            'default'     => "#000000",'transport'   => 'refresh',) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize,'link-color',array(
            'label'        => __( 'Link Color','mytheme' ),'section'    => 'colors',) ) );

        //All our sections,and controls will be added here
        $wp_customize->add_setting( 'link-hover',array(
            'default'     => "#ffffff",'link-hover',array(
            'label'        => __( 'Link Hover',) ) );

}

add_action( 'customize_register','mytheme_customize_register' );

function mytheme_customize_css() { 
    ?>
    <style type="text/css">
            /* link color style define !important if need*/
            a { color: <?php echo get_theme_mod('link-color',"#000000"); ?> !important; }
            /* link color hover effect style define !important if need*/
            a:hover { color: <?php echo get_theme_mod('link-hover',"#ffffff"); ?> !important; }
    </style>
    <?php
}
add_action( 'wp_head','mytheme_customize_css');

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。