.proto 文件定义:
message ResponseStatus {
uint32 code = 1;
string message = 2;
}
message DepositPaymentRequest {
uint32 member_id = 1;
}
message DepositPaymentResponse {
ResponseStatus status = 1;
repeated DepositMethod methods = 2;
}
message DepositMethod {
string method_name = 1;
string payment_count = 2;
repeated DepositPayment payments = 3;
}
message DepositPayment {
uint32 payment_id = 1;
string payment_name = 2;
uint32 payment_money_min = 3;
uint32 payment_money_max = 4;
}
我的PHP代码:
$status = [
'code' => 200,
'message' => 'Success'
];
$responseStatus = new ResponseStatus($status);
$depositMethods = [
[
'name' => 'name1',
'count' => 1,
'payments' => [
[
'payment_id' => 1,
'payment_name' => 'name1',
'payment_money_min' => 10,
'payment_money_max' => 5000
]
]
]
];
$depositPaymentResponse = new DepositPaymentResponse();
$result = $depositPaymentResponse->setStatus($responseStatus)
->setMethods($depositMethods)
->serializeToString();
实际: $result 没有数据,那么如何分配重复字段?
我尝试像这样使用 RepeatedField 类:
$repeatedMethods = new RepeatedField(GPBType::MESSAGE, DepositMethod::class);
但我不知道如何使用它,所以我使用数组来分配但没有成功