问题描述
我想将 google pay API 用于具有 firebase 云功能的通行证,但不幸的是,nodejs 在 google-pay/passes-rest-samples 中被严重遗漏,并且在 client libraries 中不受支持。
我能够在 PHP 示例中测试 API - 即我的服务帐户已启动并链接到我的商家帐户,但我想知道如何在 nodejs 中使用该 API:
尝试了以下操作,但我总是收到 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');