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

Media::updateNews() 方法与微信API不一致 #29

Closed
acgrid opened this issue May 24, 2015 · 1 comment
Closed

Media::updateNews() 方法与微信API不一致 #29

acgrid opened this issue May 24, 2015 · 1 comment

Comments

@acgrid
Copy link
Contributor

acgrid commented May 24, 2015

修改图文信息的方法
https://github.com/overtrue/wechat/blob/master/src/Wechat/Media.php#L179

'articles' => array($article)

对传入的数组又放入了一个新的数组中。

微信API: http://mp.weixin.qq.com/wiki/4/19a59cba020d506e767360ca1be29450.html
示例如下:

{
  "media_id":MEDIA_ID,
  "index":INDEX,
  "articles": {
       "title": TITLE,
       "thumb_media_id": THUMB_MEDIA_ID,
       "author": AUTHOR,
       "digest": DIGEST,
       "show_cover_pic": SHOW_COVER_PIC(0 / 1),
       "content": CONTENT,
       "content_source_url": CONTENT_SOURCE_URL
    }
}

注意articles键的值是一个关联数组。
也就是说发布图文消息时$article的结构是[{},{},{}],在更新时只能根据index更新各项{}。
我因为只需要发单图文信息,直接把[]去掉就可以了。
对于需要编辑多图文的客户端代码,确实有可能忘记提取元素(我一开始也写成发布和更新传入的参数一样,改了以后发现还是不对才去看的源码),感觉这样就可以偷懒了?

$article = isset($article['title']) ? $article : (isset($article[$index]) ? $article[$index] : throw something);
@overtrue
Copy link
Collaborator

@acgrid 妹的微信应该是改了这个 API,之前我故意加个 array($articles) ,我已经合并了你的提交。

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

2 participants