Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用API V3协议,当segment中,uri_template动态参数中有大写英文字母会被转换成小写英文字母 #56

Closed
jodumadie opened this issue Nov 1, 2021 · 4 comments

Comments

@jodumadie
Copy link

使用API V3协议,当segment中,uri_template动态参数中有大写英文字母会被转换成小写英文字母。

@TheNorthMemory
Copy link
Collaborator

是的,类库中的segment是大小写敏感的,含义如下:

  • 首字符大写,用于标记为interface
  • 中间字符大写,用于还原连字符hyphen(-);
  • 首尾字符是下划线understore(_),用于还原uri_template字面量字符串;
  • 特殊语法关键字,如return, /, use 需要用到 uri_template 构造;

特殊URI规则总结于 https://github.com/TheNorthMemory/wechatpay-openapi 项目README所列如下:

源URI 模版变量
secapi/mch/addInstitutionsub {addinstitutionsub} 1 addInstitutionsub
secapi/mch/modifyInstitutionsub {modifyinstitutionsub} 1 modifyInstitutionsub
secapi/mch/queryInstitutionsub {queryinstitutionsub} 1 queryInstitutionsub
v3/applyment4sub/applyment/ {stub} 2
v3/ecommerce/applyments/ {stub} 2
v3/ecommerce/subsidies/return {return} 3 return
v3/marketing/busifavor/coupons/return {return} 3 return
v3/marketing/busifavor/coupons/use {use} 4 use

建议 uri_template 保持与上述规则一致,即使用全小写及/或下划线形式描述模版字面量

Footnotes

  1. 源URI上含有I大写字符,需要用模版变量构造 2 3

  2. 源URI末尾以/结尾,需要值为用空的模版变量构造 2

  3. 源URI末尾segment单词是return,其为PHP语法关键字,需要用模版变量构造 2

  4. 源URI末尾segment单词是use,其为PHP语法关键字,需要用模版变量构造

@xy-peng xy-peng closed this as completed Nov 3, 2021
@yybawang
Copy link

yybawang commented Dec 3, 2021

有的接口的path里是有 openid 的,openid 是有大小写的了,转换后就得到一个乱掉的openid了,

我请求的支付服务商->发放优惠券接口
如图

示例

@TheNorthMemory
Copy link
Collaborator

TheNorthMemory commented Dec 3, 2021

@yybawang 有多种方式可以避免:

  1. ->v3->marketing->favor->users->_openid_->coupons->post(['openid' => 'AbcdEF12345']);

2.->v3->marketing->favor->users->{'{openid}'}->coupons->post(['openid' => 'AbcdEF12345']);

  1. ->chain('{+myurl}'->post(['myurl' => 'v3/marketing/favor/users/AbcdEF12345/coupons']);

  2. ->{'{+myurl}'}->post(['myurl' => 'v3/marketing/favor/users/AbcdEF12345/coupons']);

建议使用第一种方式,具有IDE提示.

@xy-peng
Copy link
Contributor

xy-peng commented Dec 3, 2021

看来需要增加一个常见问题,或者在链式调用的地方再加以强调。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants