管理员
论坛积分
分
威望 点
贡献值 个
金币 枚
|
提供B2B的移动商务解决方案,通过图像识别技术,通过摄像头扫描直接查询和购买商品。
$ a/ X' C) _1 R- H E: U2 [1.添加商品信息7 i# f2 ^$ H& `' Y7 X
2.添加图片
- Z1 x- n' R# T3.查询所有产品* O C' H& Q$ M* A7 {. `
4.查询某个具体产品信息* O7 b* b! Y3 P9 R' j# Q; \
5.删除某个产品
' \' T+ i. R7 ?& n& a7 H6.删除图片
- i S" D c# ^4 ^' A7.图像识别; A( M9 \4 e3 H S/ w# ?/ N
+ m( ^- v- i) z5 n图像识别API文档:https://www.juhe.cn/docs/api/id/117,申请后生成AppKey; n2 A2 |( j: e& W. Y
. _! L6 Z+ g/ ?8 o& O0 z6 i! A
PHP示例:2 `0 E& M. s* c0 n! J$ m8 ~+ Z/ p
- <!--?php
* Q' C6 i0 I2 C! L7 N - // +----------------------------------------------------------------------
, B' b4 n' d- G3 `$ }1 u - // | JuhePHP [ NO ZUO NO DIE ]
/ Z% }$ j- S" M/ }& D2 i - // +----------------------------------------------------------------------
& r/ _/ p. N$ w, g! L+ D% x - // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
' e% B% i5 }3 L1 S0 @: c - // +----------------------------------------------------------------------8 ]3 U$ R8 A/ u
- // | Author: Juhedata <info@juhe.cn-->. `, O8 h# X( g4 h6 X7 n
- // +----------------------------------------------------------------------
9 I1 d1 J" B8 ?: G2 u) O - * L1 \0 j q/ s
- //----------------------------------
% V* W# m1 Y1 d% Y9 M8 b - // 图像识别调用示例代码 - 聚合数据
+ X" U% z: W% r1 q7 x - // 在线接口文档:http://www.juhe.cn/docs/1174 Y3 S9 p J9 [4 Y7 Q n
- //----------------------------------
% X+ `8 T5 G0 P! ]& {" n - * [* O9 J% }7 d& ~# {% {- R
- header('Content-type:text/html;charset=utf-8');% Z: R! i! g9 n r$ `( [
- 7 E+ m X& A0 g
-
+ i1 H ]' Y3 `( [ - //配置您申请的appkey
! k4 R) }5 t; I/ `% ?( B+ K - $appkey = "*********************";
& Y) T( D% U& e5 h' n t. } - 1 x4 X5 Y8 U4 m A$ L% `
-
$ k1 `5 ~" J, x& |0 V -
& `% c; q2 S: ^' c8 G: a) I, U - . |0 L9 x; Q( k( L5 P& w1 f* E& i- `) W
- //************1.图像上传************
! W" h; U1 c! K - $url = "http://japi.juhe.cn/image_recognition/upload";) f1 ^& s' S; |- W
- $params = array(
; C* A; n6 p8 ~1 q) w D7 a; g - "file" => "",//上传的单张图片
/ N4 T Y1 ~6 G8 f9 b' [$ k - "key" => $appkey,//APP Key
1 `, |* T$ L9 f" a, M3 \$ P - "pname" => "",//包名& [2 y( M( u/ R M9 y( P; L/ s V3 n& V
- );: V: @) [1 P% R L! v. Z' x
- $paramstring = http_build_query($params);3 r* t9 I& ?4 v2 y
- $content = juhecurl($url,$paramstring,1);
# C5 Q0 M% i& ?& m - $result = json_decode($content,true);
" f" ~/ ]) g. w# p- g5 O! l* N - if($result){
$ d4 D& ~! G6 X- C* \ - if($result['error_code']=='0'){! F9 j4 D* z4 m. p" C: D
- print_r($result);
" w4 f- o, S) b0 U - }else{( ?% X6 y8 M' F/ b$ i7 D& f
- echo $result['error_code'].":".$result['reason'];4 [" q. U+ r$ G/ c( V
- }
" u- a, _2 Z+ A0 g$ e7 C5 ~6 H - }else{
+ \- e# |; }- y4 e - echo "请求失败";. `" I2 e& y) P" L
- }( J$ C/ B! G# C$ T% t5 i7 L- _ _
- //**************************************************7 E6 R/ n2 [$ d1 P7 U. I& W
- . U( d, g# E p9 h" j: E
- 2 w0 Y3 X& c+ i
-
# N' b6 ?- t" P" m# E -
8 l- R: a+ Z* H- q9 U - //************2.查寻上传图像信息************$ n9 F' \' K q) M" Y3 D( s6 ~
- $url = "http://japi.juhe.cn/image_recognition/findAll";
+ B5 f Y4 \8 a; B m' v - $params = array( a' }) _ I, `% T
- "key" => $appkey,//APP Key
! O& a/ k' N$ Z - );
0 ~3 e. p7 y2 F2 i0 n3 I, u - $paramstring = http_build_query($params);: Y/ @: w2 ?+ ?3 U. a
- $content = juhecurl($url,$paramstring);
. Z9 P% S8 i2 W! C6 c' P - $result = json_decode($content,true);$ H1 I P, Z! d5 y" _' W9 B
- if($result){0 F1 r1 K" k0 Q& r9 w
- if($result['error_code']=='0'){ T. S( d- \" d5 C( t" n2 i
- print_r($result);2 c: r( O/ g) K; _: f1 q" g a
- }else{% K1 Y9 [0 h' `; |- L. y& z
- echo $result['error_code'].":".$result['reason'];
% D, c' T( _3 Q% } - }
; k' E# h& D4 a9 T* j# o - }else{
. c! P) \* ^0 H4 M$ x - echo "请求失败";" {2 t7 Z6 v3 z- l
- }0 S6 m8 Y' `$ w% ?: t* ?
- //**************************************************" U9 u, j7 e3 z- r/ Z$ e' O' P
-
* |: B8 \& C0 {0 K' O8 k - : @: G; w4 F- f, i8 y0 b4 w3 {
- & J7 V+ n! [ A: e$ I
- 8 \# S/ e1 e; Z+ |
- //************3.删除图像信息************+ D$ L4 |# F0 C( U4 A: J2 ?
- $url = "http://japi.juhe.cn/image_recognition/delete";
, P+ a( o2 E2 D- h2 r4 p- Q - $params = array(
( l4 |0 M) @8 g% I - "key" => $appkey,//APP Key
* H) k# N" ~5 Z4 E* Y7 O6 C - "imageId" => "",//图片ID
" b. W% K; g, D9 ]4 A - );
+ o. n; v# u1 J& c. } - $paramstring = http_build_query($params);
8 `: Q% ^' \. V) E - $content = juhecurl($url,$paramstring);! Z d5 M" w5 A
- $result = json_decode($content,true);
4 p! `! b2 Q6 B$ W& ?% T5 p - if($result){
% g# l/ `) f( @4 Z6 D7 F - if($result['error_code']=='0'){
: l$ l7 N0 L( T8 I* C$ M3 G2 X2 w - print_r($result);
# ^1 h3 }# z$ z7 Q - }else{
1 ~+ G6 T5 P' R, V. _9 m: g! O/ y - echo $result['error_code'].":".$result['reason'];
: r5 h$ Y- a$ N) r& n# W - }: |6 p- P; S) z+ x
- }else{
: S5 e0 P) C3 H3 ]/ q - echo "请求失败";( ?* e1 a: y$ F
- }8 z w$ g" d, V- e$ `
- //**************************************************) z5 V* R) l3 d+ d6 @& h
-
% y8 v( \6 z1 _0 s4 ]; l6 n - & t5 [) p0 s) T( g: n+ m) @
-
, `4 Y/ R/ S N( \- E4 Y -
+ M ?$ L. X; ~' z2 u - //************4.图像识别************1 @1 `% {2 _! t7 S3 h
- $url = "http://japi.juhe.cn/image_recognition/check";
3 r* }% [( x4 z1 x6 K9 H - $params = array(
' {" L `: L5 D - "file" => "",//上传的图片
6 b0 O( x5 B/ O3 }/ M5 W+ G1 m1 D - "key" => $appkey,//APP Key
, N# [7 \/ w5 B - "pname" => "",//包名" b: N7 Z: k- G; p
- "device_name" => "",//设备名称(如android OS或iphone OS)- u. ^) @! r( v) ^& g& X
- "device_version" => "",//设备版本(如:4.0.3)
& s; o3 Z& p" s. u* J - "latitude" => "",//纬度& r) s6 }6 I; j c0 E6 N) q
- "longitude" => "",//经度* |3 c" t5 ?; I7 }) Q A
- "uuid" => "",//设备id
$ l- F8 ^+ Q5 g e1 l - "zone" => "",//请求地区2 n$ `7 X6 a. p. w$ x1 C, b
- );
& ?5 b8 F( z6 A) ~7 ^ - $paramstring = http_build_query($params);. Y4 I# n# |, W, C" V
- $content = juhecurl($url,$paramstring,1);
/ K( |" F" x. `2 [* e9 Y: p3 I - $result = json_decode($content,true);
, x3 P7 ]2 R7 _5 o - if($result){+ }+ B! R7 T9 u) x$ m8 {
- if($result['error_code']=='0'){7 ^5 U" \% m! m# U# l2 o
- print_r($result);
, q* a+ e; r) l( J( h - }else{/ _3 w7 c& O& \1 K
- echo $result['error_code'].":".$result['reason'];0 P: w6 g* l7 B
- }4 W3 n, a; g5 e7 M
- }else{, C' }$ e- H8 a- C, N0 S: ?2 j
- echo "请求失败";, m3 ]7 p, ^% z1 W
- }
* G9 F7 a( O' H+ ? - //**************************************************
; w1 u4 ^2 i6 h/ j' X" l/ u' k -
, F# [ g3 V7 q. |/ O$ R -
/ n# {" [: h- ?& n& h - 7 r; K3 y8 b' D: u
-
7 o' I, f0 m0 L2 Y7 J- P - 6 v& [4 J% `3 o* @% R0 F
- /**$ b/ x: @: }# I6 T3 B
- * 请求接口返回内容' S: t* _* j- E: O! I
- * @param string $url [请求的URL地址]
% |2 j" _2 K% ?8 j6 @" Z# w; R i - * @param string $params [请求的参数]
J9 q- t5 n, `5 p+ q/ @) @2 O5 D - * @param int $ipost [是否采用POST形式]6 O8 t6 }. @% a" ]
- * @return string
* U: D% K/ q3 c4 ]1 F - */! ^( ?) [1 {6 |" K
- function juhecurl($url,$params=false,$ispost=0){- A- N8 R1 Z, l
- $httpInfo = array();
) d1 [" p3 T6 G, R9 ` - $ch = curl_init();% x& U# P C9 P% c$ U5 Q
- - M: \- O" @4 q/ x
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
; W$ ^$ {2 Y# Z) f - curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );! V3 a9 j6 T+ \0 W% B
- curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); m/ R' a2 P6 x {
- curl_setopt( $ch, CURLOPT_TIMEOUT , 60);) p, t1 A" [% _7 H: c0 B" P
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
+ P# D+ G2 E4 `; O - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
5 c0 Z3 T S; ~) l* C K - if( $ispost ) l; B( q# k- c
- {6 w& u {: L! Q- \( J2 r. l
- curl_setopt( $ch , CURLOPT_POST , true );
" M M9 {# h- F' s - curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
8 a, i( c( K+ ?( X - curl_setopt( $ch , CURLOPT_URL , $url );- Z$ q7 b+ G' a0 J3 o! [' l
- }
* Z7 F, I( R* {: D# [2 ` - else. Q! {0 q- \ @
- {
* y: I: n, b4 N+ \( ~, V% Z$ i - if($params){
# m% u6 B1 `' Z; y9 |( k - curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
# `! Y# G# q4 N5 @% ]3 U5 Q' c! v - }else{
" c1 ]" f, F# J+ I0 d0 r - curl_setopt( $ch , CURLOPT_URL , $url);
8 c3 N9 n7 V8 Z0 B - }. N$ I6 R( s+ B
- }
5 d% y# b9 d8 S3 v6 A" ` - $response = curl_exec( $ch );
$ t0 t' O2 e$ a: g" ~ - if ($response === FALSE) {
/ ?8 D7 C' p$ y+ u - //echo "cURL Error: " . curl_error($ch);. I$ I2 }7 h- J U& T
- return false;3 ] T% {, f# o/ C2 E
- }
) X" Y# k( \: Z* }' U) |; [" F- n( c - $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );" X1 [* a/ N- W, @ b+ q p
- $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
8 R3 D6 k; z6 g+ T- s - curl_close( $ch );
" g/ M/ b0 l# U - return $response;
/ O9 O5 F0 B8 O! H, b6 N - }
复制代码
0 E$ u. V6 W1 p8 s& g6 e1 U. p6 A2 @+ e
|
|