管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。/ S: m$ D# w% f B$ ^- V
1.添加商品信息0 e$ S& T: W# ?* ~/ x
2.添加图片
" }8 f) e$ ]9 b* o4 p& h7 P9 L3.查询所有产品' A% X8 b9 A L ~& C4 U
4.查询某个具体产品信息
0 e8 o+ O2 Z* h& T8 Y1 S% V, y. U5.删除某个产品
; \" V( j$ b& d% L6.删除图片
4 P: v1 _8 a: p+ O7.图像识别, x% z% x" B3 x9 }: n6 ]
6 j8 c% ~) H8 b5 R; b( N n5 @
图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey
. `8 D5 j+ V& y' V. M9 D- F5 c$ N% n) D- {
PHP示例:
5 T* |0 e0 \! z( t. m8 I' `- <!--?php9 E. D& a) a2 p% p
- // +----------------------------------------------------------------------
4 c3 a3 o1 }3 X% X* E$ Q6 ?/ y - // | JuhePHP [ NO ZUO NO DIE ]
2 m; w ? E$ Z" k% d* D - // +----------------------------------------------------------------------
8 _1 `' l) t% y" @" E; g6 c$ S - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.' w1 @7 p! Y) L8 M; @7 }7 d
- // +----------------------------------------------------------------------6 w, {! _- O( N
- // | Author: Juhedata <info@juhe.cn-->7 [( N- y3 t" K) A
- // +----------------------------------------------------------------------
7 b1 m8 L) g% t; W -
" s9 q6 H% V" G8 A) [ - //----------------------------------4 v) |0 ~, R$ H3 j4 t; N/ w. z) {
- // 图像识别调用示例代码 - 聚合数据
) m" O+ C1 W, i: m - // 在线接口文档:http://www.juhe.cn/docs/117( ^3 X# x3 M% L5 g$ |
- //----------------------------------9 M/ T* E3 t- I. w& s' M- k
-
/ T3 }6 B1 u* [7 X9 h - header('Content-type:text/html;charset=utf-8');
$ X7 V: e' c0 K& @9 h3 O - 6 X% l! C; R# R! e4 x2 g
-
: @) K9 j; R9 q$ ~4 c: j+ n( v - //配置您申请的appkey4 a4 ]! D: a6 C* @
- $appkey = "*********************";
5 I3 a8 p. p6 Y- x* I3 }7 W6 f8 S -
7 j$ d3 f7 Z6 Y9 [5 F7 C - 7 I/ z" S8 [0 _/ n; c% h1 K, j7 g
-
d7 V- y$ r) R6 r - 8 W0 A% F; r+ t' y, @9 t4 n2 l R
- //************1.图像上传************
# H4 U8 y5 J7 @) E6 R - $url = "http://japi.juhe.cn/image_recognition/upload";
3 Z0 i4 M, L/ ~4 D( ~ - $params = array(
7 q- {9 {4 }- Y, c' S - "file" => "",//上传的单张图片
$ M5 w/ D. A) U, ] - "key" => $appkey,//APP Key
' M3 B0 [/ J! p. {5 a4 F/ _3 @' K - "pname" => "",//包名; ^3 J" {! R+ I" u2 W/ i% d
- );
) x0 J. m# J* \3 x/ W' Q - $paramstring = http_build_query($params);
, n& a- W/ J- k% o+ B: U - $content = juhecurl($url,$paramstring,1);1 T. x d$ {; [
- $result = json_decode($content,true);5 S: [# _: e7 Y" e
- if($result){4 G$ m3 T& C3 K) z* \3 ]* G
- if($result['error_code']=='0'){
9 s' q- Z8 k0 T, T; P - print_r($result);1 k: D- O6 E) f# R6 J2 C' ~
- }else{
$ m4 } d U0 m - echo $result['error_code'].":".$result['reason'];6 N2 h9 s' s _% n' A
- }# f4 `, q: M2 @' [: {5 x
- }else{
" s7 m+ X% b9 D2 ^+ e - echo "请求失败";
7 Y; V: Q( U0 k1 @+ A - }. g1 h d# l. q) W4 f
- //**************************************************/ f' D" y2 `0 o
-
% F l8 i% f% j8 t! C0 s/ _0 \ -
' M4 g& c- v9 x; i -
5 R$ k2 ]- C' N4 c -
, \8 O' F" _/ v8 `+ M, [( V - //************2.查寻上传图像信息************7 l. M8 N* m- C
- $url = "http://japi.juhe.cn/image_recognition/findAll";
. o* Q& x3 }0 L" R# e+ [* r - $params = array(
* Z6 ~9 ~8 O: R0 z g - "key" => $appkey,//APP Key9 Z' E* T; S! f7 l/ R
- );9 K" C3 m# b9 C# T& H) l/ ~" o- b
- $paramstring = http_build_query($params);
. U4 c5 ]4 c- o& I3 \ - $content = juhecurl($url,$paramstring);
- T- Q4 h" Y0 Q! L, R - $result = json_decode($content,true);
7 s8 I4 ?2 Y5 A8 j1 p - if($result){
, \% v0 i, W: b* U, @ - if($result['error_code']=='0'){
! N1 m5 F& ~3 h s4 t& j - print_r($result);
( ~/ H6 ~$ @; c# x+ J5 l' ] - }else{" C9 f. P& ^& I# i4 q3 ]- S- @
- echo $result['error_code'].":".$result['reason'];
6 [8 R- n6 u8 Q% q0 Z2 P - }6 W3 m8 F; Y f! k# c
- }else{ N5 J# d4 e& w, C1 O( ~
- echo "请求失败";
. _& X: ]8 u' c! h - }' W3 F& h. P+ S# s+ e r8 c9 F
- //**************************************************2 o8 j' \+ r' o( W, ~. t
- 3 b ^9 b) W/ _ z" }6 ?- p
- ! [# F' J, s9 C- U) Q' ]
-
5 \8 J' I' Q" B; q& X2 l -
! S4 y( [& K, | _! |5 J - //************3.删除图像信息************
! H& n$ d0 Z6 O- W$ k- u/ R - $url = "http://japi.juhe.cn/image_recognition/delete";# C! G7 [* A# f3 R: G
- $params = array(
" Q9 }9 G% K# m - "key" => $appkey,//APP Key, V' A p: V' B
- "imageId" => "",//图片ID
# c2 `/ q0 S% ~* \ - );
. y- X! I7 M# @/ n3 ~. ? - $paramstring = http_build_query($params);, ~- E+ J, A9 D: M
- $content = juhecurl($url,$paramstring);
. S, k0 n; w6 ~$ I1 ~ - $result = json_decode($content,true);
# h. ]" A }+ b# ^ - if($result){
& z6 a" J. m+ \9 i - if($result['error_code']=='0'){) w& Y J9 T) u o- g: I# ?9 g' E
- print_r($result);
; G( ^5 l& r6 y4 ` - }else{' _! s: a3 s* @% t3 n p; s5 ?6 V
- echo $result['error_code'].":".$result['reason'];
8 U7 F, D+ \ ]# E0 Y - }( s' b" j# [: D
- }else{
: u; c W4 ^; | - echo "请求失败"; W1 N; w6 H$ Y4 r/ u: [
- }
; C7 T) I% \5 H7 j% S% W( g - //**************************************************9 Z' V8 h2 f; u: g2 E
-
, i; u0 Q$ a, R! ?( b1 D6 Q4 b' i, w4 Y - ( A/ B6 E- ]* B) n. D7 r e7 y
-
6 W' @( i5 T( G3 }* o7 D -
4 l' G3 A: r3 |: t/ v5 e7 ] - //************4.图像识别************
$ Z" y: d9 j1 i" r- r - $url = "http://japi.juhe.cn/image_recognition/check";
% S! u. S3 ]* w9 l) I. y# X - $params = array(
* {& T6 [( x- L& x$ | - "file" => "",//上传的图片
5 t. r! b5 q7 L" f2 \: [% ] - "key" => $appkey,//APP Key
" O( z2 ~$ U: `3 l8 Y - "pname" => "",//包名* o! z5 q" Z( ^
- "device_name" => "",//设备名称(如android OS或iphone OS)
) q2 f6 W" K0 o. X# G - "device_version" => "",//设备版本(如:4.0.3)
$ R+ {+ @' G# ^/ k/ H - "latitude" => "",//纬度: k1 T2 k& G) ~( Z
- "longitude" => "",//经度
) P0 x8 F" R) A" y - "uuid" => "",//设备id
1 R. q* h" o& A. m. S - "zone" => "",//请求地区( n4 d4 H2 `4 D @
- );
( Z, P8 T$ H+ ~2 X x6 Q+ W - $paramstring = http_build_query($params);
* h! M& c. k: C7 _8 |% } - $content = juhecurl($url,$paramstring,1);
8 d* a4 h) ^$ y* l- | - $result = json_decode($content,true);
7 W# T+ x3 W( G/ j# M - if($result){1 m% P4 d. P1 q3 g9 F) _- z7 Q
- if($result['error_code']=='0'){
4 r4 q; u% K# h8 o - print_r($result);- X0 N5 e4 y9 P
- }else{
9 u3 R% B3 A* A [; f: B% ?* {" ? - echo $result['error_code'].":".$result['reason'];
. R; X! `- n# |7 \. G }8 l0 [ - }
5 m8 v9 z s8 S8 e0 n' j - }else{" l: G( ]/ f6 y
- echo "请求失败";5 Y" m0 Q2 n3 r5 e& P( |6 c
- }$ E+ \1 G5 c; A+ k9 c0 o
- //**************************************************3 C) P3 G7 x' e( [; W Z
-
" q4 L* V# S2 T+ \% k - D+ D5 T8 e$ D* t& W+ Y
- & ] r7 M. J1 a$ ]
- ; T/ S$ @, e$ `9 ~# |+ A4 P
- # C |9 L. b5 b# B! c/ ]/ f
- /**0 Q- Y; C0 V8 j6 c8 J
- * 请求接口返回内容/ Y% F0 T' @3 z3 k- C5 K2 |( ]
- * @param string $url [请求的URL地址]' h: o$ Q) q* t
- * @param string $params [请求的参数]
! u* q. {6 j* V4 B) H - * @param int $ipost [是否采用POST形式]/ \& y+ Z( ]6 [2 t/ q3 C$ ?
- * @return string- f) ~% w' ]4 N5 O# W
- */# h( V/ |! t% V- f
- function juhecurl($url,$params=false,$ispost=0){' [+ {- E7 _ X& Q) Z" j1 w" x% x
- $httpInfo = array();2 l) p" \$ J+ K0 i5 I C; }
- $ch = curl_init();
$ t$ p7 [8 u6 y; c - - {) p' w; T8 o- E
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
. s, s4 g% e5 A c" P6 w y4 z6 F - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );% b% p' l( c6 L6 C8 u- g. u
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );5 m5 A l H' ^
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);( R }3 X+ e- K; D
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
/ w5 F% w5 i: E( r1 E$ _ - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
! r3 c# d& `! ^# F0 M. I3 V - if( $ispost )( Q0 G- {0 O( d, k/ ^' z
- {. ~% d) t" N7 K- n" `/ {
- curl_setopt( $ch , CURLOPT_POST , true );0 v/ @. z, J. ~ N
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
' p4 J% {" G' [' C( S1 h7 k/ \ - curl_setopt( $ch , CURLOPT_URL , $url );. v" ?% d: R6 j* |0 l
- }8 e6 R4 q# n1 Y, i. G1 c
- else8 P6 p$ t0 M4 \+ @8 J; e; N$ \
- {$ q" s& i- \& C
- if($params){
2 a4 p+ }1 Q6 ?, U1 F - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
8 e7 v y: B0 j x9 j8 K g - }else{& c( ^; ~8 }8 V& a* {
- curl_setopt( $ch , CURLOPT_URL , $url);
. z' ?* o# u5 P* m! @" H: s8 f - }
: ~$ s0 r) y0 B - }
" u; o: F0 f2 }# m0 F$ C, N - $response = curl_exec( $ch );
# `8 s6 h5 F# N$ K: ^ - if ($response === FALSE) {8 v& n% ]& ^" a6 r4 x+ e: t
- //echo "cURL Error: " . curl_error($ch);& I; L( h4 ~8 A/ R
- return false;
" i- e) q8 m: m9 N7 a4 H" Y - }
, j( O( O( ?; }. v - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );+ c! {4 X2 E, Z& o3 l0 {
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
4 W# U9 s+ u+ d7 n. A: {! m - curl_close( $ch );
2 r5 @1 G7 C1 [& @ - return $response;
) D h3 I5 Y, U* q2 a, |- Y% I - }
复制代码 3 B2 [% ]9 d3 c# q& k2 L
7 i7 q7 g3 Y7 K" n I6 K1 j3 L9 I |
|