PHP应用添加Google Wallet通用卡时TextModuleData不显示求助
Google Wallet通用卡TextModuleData不显示问题
我在PHP网站上集成Google Wallet通用卡,功能基本实现,但TextModuleData内容无法显示在卡片上。基于官方PHP通用卡示例修改后,卡片的名称、Logo等内容均可正常展示,唯独文本模块缺失。
核心代码
调用代码
$googlepass = new GooglePass(); $googlepass->createJWTNewObjects('issuer_id', 'my_class_suffix', $randomString);
GooglePass类核心方法
class GooglePass { // 授权相关代码 public function createJwtNewObjects(string $issuerId, string $classSuffix, string $objectSuffix, $user) { // 更多属性说明见官方文档 $newObject = new Google_Service_Walletobjects_GenericObject([ 'id' => "{$issuerId}.{$objectSuffix}", 'classId' => "{$issuerId}.{$classSuffix}", 'state' => 'ACTIVE', 'header' => new Google_Service_Walletobjects_LocalizedString([ 'defaultValue' => new Google_Service_Walletobjects_TranslatedString([ 'language' => 'en-US', 'value' => $user->name, ]) ]), 'textModulesData' => [ new Google_Service_Walletobjects_TextModuleData([ 'header' => 'Location', 'body' => $user->location, 'id' => 'location' ]), new Google_Service_Walletobjects_TextModuleData([ 'header' => 'Other Details', 'body' => $user->detail, 'id' => 'otherDetails' ]) ] ]); // 使用服务账号凭据签署JWT $serviceAccount = json_decode(file_get_contents($this->keyFilePath), true); // 创建JWT键值对数组 $claims = [ 'iss' => $serviceAccount['client_email'], 'aud' => 'google', 'origins' => ['www.mysite.com'], 'typ' => 'savetowallet', 'payload' => [ 'genericObjects' => [ $newObject ] ] ]; $token = JWT::encode( $claims, $serviceAccount['private_key'], 'RS256' ); print "Add to Google Wallet link\n"; print "https://pay.google.com/gp/v/save/{$token}"; return "https://pay.google.com/gp/v/save/{$token}"; } }
疑问与尝试
我猜测问题出在需要创建或更新GenericClass,但不确定针对500+用户,是否需要为每个用户分别创建类和对象,还是可以复用同一个类。
尝试添加以下GenericClass代码后,创建卡片时出现**"Something went wrong. Please try again."**错误:
$newClass = new Google_Service_Walletobjects_GenericClass([ 'id' => "{$issuerId}.{$classSuffix}", 'classTemplateInfo' => [ 'cardTemplateOverride' => [ 'cardRowTemplateInfos' => [ [ 'twoItems' => [ 'startItem' => [ 'firstValue' => [ 'fields' => [ [ 'fieldPath' => "object.textModulesData['points']", ], ], ], ], 'endItem' => [ 'firstValue' => [ 'fields' => [ [ 'fieldPath' => "object.textModulesData['contacts']", ], ], ], ], ], ], ], ], ], ]);
相关文档说明不够清晰,希望得到正确的解决方向。
内容的提问来源于stack exchange,提问作者supazu
相关产品推荐
相关产品推荐

