質問

We are implementing share functionality with TencentQQ using their static share URL. We have an encoded URL: "http://www.testurl.com/product/this-is-a-product-%E7%9F%AD%E8%A3%A4/id-000000"

When this link is shared via TencentQQ using this link: http://share.v.t.qq.com/index.php?c=share&a=index&url=http://www.testurl.com/product/this-is-a-product-%E7%9F%AD%E8%A3%A4/id-000000&title=This%20is%20a%20test&appkey=000000000

You will see on your feed that the URL is being split at the start of the Mandarin characters. URL Being Split

I imagine that they are using decodeURIComponent when processing the URL, which I notice has the same effect when executed in Chrome's dev tools console:

Chrome Dev Tools

I guess the question here is -- am I doing something wrong in encoding this URL? Is there a reason that the URL is being split at the start of the Mandarin characters?

役に立ちましたか?

解決

Your URL isn't encoded, it looks like it was encoded because it uses non-ASCII/non-Latin characters, any URL that has another URL inside as a parameter needs to be encoded, long story short, here is the solution:

function urlShare(url,title,appkey){
    return 'http://share.v.t.qq.com/index.php?c=share&a=index&url='+encodeURIComponent(url)+'&title='+encodeURIComponent(title)+'&appkey='+appkey
}

Just call this function with the URL, Title and appkey (don't know if the appkey need to be encoded):

urlShare('http://www.testurl.com/product/this-is-a-product-%E7%9F%AD%E8%A3%A4','A Title','id-000000')

It will return a safe URL that actually works.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top